在shell脚本子进程中解决sudo问题

时间:2015-09-06 19:48:26

标签: linux bash shell scripting

所以我问这个的原因是因为我同时运行两个持久的程序,在子进程上正在运行一个需要sudo权限的程序。

#!/bin/bash
echo "Name the file:"
read filename
while [[ 1 -lt 2 ]]
do
 if [ -f /home/max/dump/$filename.eth ]; then
  echo "File already exist."
  read filename
 else
  break
 fi
done 
#Now calling a new terminal for dumping

gnome-terminal --title="tcpdump" -e "sh /home/max/dump/dump.sh  $filename.eth"
ping -c 1 0 > /dev/null **Waiting for tcpdump to create file**
#Packet analysis program is being executed

脚本dump.sh

#!/bin/bash
filename=$1
echo password | sudo tcpdump -i 2 -s 60000 -w /home/max/dump/$filename -U 
host 192.168.3.2
#Sudo still asks me for my password though password is piped into stdin

0 个答案:

没有答案