0

I have this shell script which ssh to other server, find few specific files(.seq files older than 50 mnts) and writes their name to another file.

#! /usr/bin/bash

while read line
do
#echo $line
if [[ $line =~ ^#  ]];
then
#echo $line;
continue;

else
serverIP=`echo $line|cut -d',' -f1`
userID=`echo $line|cut -d',' -f2`
fi
done < sftp.conf

sshpass -p red32hat ssh $userID@$serverIP
cd ./perl
for files in `find -name "*.seq" -mmin +50`
do
#sshpass -p red32hat scp *.seq root@rinacac-test:/root/perl
echo $files>>abcde.txt
done
exit;
#EOF

Now problem is that when I run it.. neither it writes to abcde.txt file nor it is exiting from the remote server. when I manually execute the exit command...it exists saying "perl no such file or directory"... while I have perl sub directory in my home directory.. other thing is when I run the for loop portion of the script on the 2nd server(by directly logging into it) it is working fine and writing to abcde.txt filr...please help...

2
  • 1
    There's a lot wrong with this, most notably the "-p" thing that you are doing here which compromises your password. I think the biggest source of confusion for you here, though, is which commands are executed locally vs remotely and which files exist where the script is run vs on the remote server. Commented Aug 19, 2014 at 9:39
  • hi.. yes this password is for testing purpose only... also all the seq files & abcde.txt are located on the .perl directory on the remote server...so there should be no confusion....thanks
    – Geetika
    Commented Aug 19, 2014 at 9:53

1 Answer 1

0

ssh takes commands either on standard input or as the last parameter. You can therefore do this (very dynamic but tricky to get the expansions right):

ssh user@host <<EOF
some
custom
commands
EOF

or this (less dynamic but can take simple parameters without escaping):

scp my_script.sh user@host:
ssh user@host './my_script.sh'
1
  • Eralier I used it with here doc. only but it was not executing the script on the remote server... your 2nd option has worked for me...thanks a lot for your help... :)
    – Geetika
    Commented Aug 20, 2014 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.