sudo is not a shell. Feed it the string cat /tmp/tmp.file >> filename and it will look for a file named cat /tmp/tmp.file >> filename and complain that no such file exists.
Don't run script with sudo, use sudo to run scripts.
sudo is not a shell. Feed it the string cat /tmp/tmp.file >> filename and it will look for a file named cat /tmp/tmp.file >> filename and complain that no such file exists.
Don't run script with sudo, use sudo to run scripts.
I m sorry but that was difficult for me to understand.
sudo is not a shell and therefore does not understand redirection (>>/etc/logger) and when you pass the command cat /tmp/tmp.file >>/etc/logger to it in quotes, it sees >>/etc/logger as part of the command name. Instead what you could do is use sudo to run a shell who does this for you:
Similar to what Corona688 suggested, if cat /tmp/tmp.file >>/etc/logger is part of a shell script, then you could use sudo /path/to/script to make it happen, since running a script will invoke a new shell that will run as root and that will interpret that shell script.
Last edited by Scrutinizer; 12-17-2016 at 02:44 AM..
Additionally, if you run this:-
... what you are trying to do is to run cat with privileges so it can open whatever file out want, HOWEVER the >> is in your current, non-privileged shell so if you cannot open the file, then you will get the bash: /etc/logger: Permission denied seen in post 1
You haven't answered vbe's question about what /etc/logger is. Is this just a plain log file, or are you trying to write to the system logs? If it is the latter, overwriting/appending to it would be a bad thing. Usually /etc contains configuration information that you would not want to routinely overwrite/append. Depending on your actual desires, this is more likely to be a file in /var somewhere.
Hello i am having an issue with bash script and this is the code
now=$(cat hosts1.txt | awk '{print $2;}')
while read n ;do
ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers'
When i execute only part with cat, it... (8 Replies)
Hi,
I am trying to run a command within my KSH script as another user due to permission issues, now both users are non root. I have tried the following command and was unsuccessful:
echo "<password>" | sudo -S -u <username> -k command
Can I use sudo to run a command as a non-root user? (5 Replies)
Hi ,
I am trying to stop and start a process using the below code. I have sudo access on my machine
## PID = process id
echo "$PASSWD" | sudo -S kill -9 <PID>
echo "$PASSWD" | sudo -S /opt/abc/startserver
/opt/abc/startserver: error while loading shared libraries: librts.so: cannot open... (6 Replies)
Hi,
I am using solaris 10 and bash shell.Script execution follows below.Initially it will check whether a directory exists or not if does not exist it will create it.(This I have completed)
Second step:I have four users say user1,user2,user3,user4.Script should prompt for the user id and... (11 Replies)
Hi,
We need to execute a root commmand to change the expiry period of a user but we are getting error as permission denied
Q How can we execute a root command by a normal user ? :mad:
any thing or suggestion will be good .... :b: (3 Replies)
Hi All
I have written one shell script for GPRS route add is given below named GPRSRouteSet.sh
URL="www.google.com"
VBURL="10.5.2.211"
echo "Setting route for $URL for GPRS"
URL_Address=`nslookup $URL|grep Address:|grep -v "#"|awk -F " " '{print $2}'|head -1`
echo "Executing ... (3 Replies)
i have logged in as user.
I want to write a script to login into root and execute commands for eg. ifconfig or other command.
kindly help me out. (6 Replies)
I don't know why the following shell script doesn't work. Could you please help me out?
#!/usr/bin/ksh
test="cal > /tmp/tmp.txt 2>&1"
$test
I know it will work for the following format:
#!/usr/bin/ksh
cal > /tmp/tmp.txt 2>&1
However, I need to get the command from the user in... (1 Reply)
I want give rights for the maint user to execute the "ping" command. Currently root user can execute the "ping" command, but the maint user is not able to execute the command. (3 Replies)