after sudo ing to other user $1 is not available for use in the next statement in a shell script
The act of sudoing creates a new shell so the command line parameters are not transferred. Depending on how sudo is executed, the child environment is inherited from the parent. If so, before executing the sudo, try this: export myvar=$1
Do you now see myvar after executing the sudo:
echo $myvar
In worst case, before executing the sudo, create the myvar in a file:
echo "myvar=$1" > /tmp/nails.txt
Now, you can source this after your sudo command creates a new shell:
. /tmp/nails.txt
Let me know if you have any comments or questions.
hi, Thanks for ur response. Its WorkInG
Hi, I have two scripts in serverA where one of it does ssh to serverB and runs other script over there. In this process i have scp in the second script to copy file from serverB to serverA.
I have an issue in scp'ing file from serverA to serverB.
It gives me an error :
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
lost connection
thanks in advance
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |