[SSH] Accessing remote directory with user-passed path
Hi everybody,
Currently, I have a script which access a remote computer via SSH, go to a folder already defined in the code and then executes a program in it, just like that:
It executes fine, but now I want to pass an argument in the command line call. which is the name of the folder to "cd" to and the name of the file to run. So I tried the following:
, which doesn't work. It's as if after the "ssh user@host << EOI" line the script lost knowledge of the variable $dir as well as $1.
I'm pretty noob in shell scripting, so would you know any way to solve this?
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)
I can ssh to another directory by doing the following:
for server in server1; do ssh -t $server1 "cd /tmp; 'ls'";done
However, if I try to do it as another user it fails:
I have tried:
for server in server1
do
dir=$(su - nbadaccount -c "ssh $server `cd '/tmp/TSTCON'` " )
pwd... (3 Replies)
Please help me to resolve below the issue in script
ssh user@server ' cd path;j=0; for i in *;do;d=`du -sh $i | \
awk '{print( $1 )}'`;p=$d'|'$i;j=`expr $j + 1 `;arr=$p;echo ${arr};done' (1 Reply)
Hi all,
Really hope someone can help me, i have been trying lots of things and just cant seem to nail it - and for something that seems straight forward....
Anyway, scenario is I need to log onto a second machine (remote server) from main workstation. Once logged in I need to run a batch... (2 Replies)
I have a task requiring that USER_A run a script, which connects to HOST_B as USER_B and does not ask for a password.
If I am logged in on HOST_A as USER_B, I can connect to HOST_B without a password, no problem. However, if I try running ssh with the command line "ssh USER_B@HOST_B" while... (3 Replies)
Hi,
Can you please help. I am scripting in sh and I am trying to simply copy one directory to another but for some reason my variables are not recognised?
echo "The latest version of the program is being found......."
cd $SOFTWARE/src/$progname
version=`ls $SOFTWARE/src/$progname | grep... (13 Replies)
Hey Everyone,
I have found this script online that has almost all the features I am looking for. However, I do not know enough expect to debug the problem.
http://linuxgazette.net/100/misc/tips/sshtool.expect.txt
First, it Traps out after it collects the user's password. I do not know... (0 Replies)