I want to run testcmd.sh on remote host (Testhost) using the following command:

ssh test@Testhost 'bash -s' < /test/testcmd

But I get the below error :

!!!!!Running MASTERCMD!!!!!
bash: line 31: /test/PROCESSLIST: No such file or directory

I dont want to have the PROCESSLIST file placed locally on the Testhost. How can I overcome this?

Cat Testcmd is below:

echo "!!!!!Running MASTERCMD!!!!!"

while read proc; do
        if (( 0 == $(ps -ef | grep -v grep | grep -c /test/$proc) )); then
                echo "!!!!! $proc down on  TU  !!!!!"
           echo "!!!!!! $proc is still running on  TU!!!!!"
#echo "Not checked"

done < /test/PROCESSLIST
  • Have you tried prefixing your whole command with cat /test/PROCESSLIST | ? At first glance that may help. – Mark Aug 24 '15 at 4:02

When the script /test/testcmd runs on the remote host it needs a /test/PROCESSLIST file in the remote host, in the same way it needs it in the local host (while [...]; do [...]; done < /test/PROCESSLIST).

That's what the error is about, but going further the script is going to break even when fixed this, since it also needs multiple /test/$proc files, whose actual names are determined at run-time based on /test/PROCESSLIST's content (if [...] grep -c /test/$proc [...]; then [...]; else [...]; fi).

In the end, you need to copy your local /test folder to the remote host:

scp -r /test test@Testhost:/test

However you'll very likely need to be root on the remote host in order to be able to copy it to /:

scp -r /test root@Testhost:/test

However root might be disabled / have no password set on the remote host; so a workaround would be to copy the folder in test's home directory and to copy it to / using sudo:

scp -r /test test@Testhost:~/test
ssh -t test@Testhost sudo mv ~/test /test
  • @kos...i have added scp command in the script and it doesnt work when called form the script but when i execute the command it works. scp /test/PROCESSLIST test@Testhost:/tmp/PROCESSLIST – canonical Aug 24 '15 at 14:15
  • @canonical It doesn't work because the script it's executed on the remote host, while the scp command I posted is meant to be executed from the local host once in order to copy the necessary files to the remote host. In fact it works because you've copied the files already, you should remove the scp command from the script – kos Aug 24 '15 at 14:22
  • @canonical Also I see you didn't accept any answer to your questions so far. Consider accepting answers if they worked for you and to upvote them as well along with any other useful answer you've received to your questions; accepting is how you can indicate that an answers worked for you, while upvoting is how you can indicate whether an answer was useful, and of course they are both a way to give reputation to the user who posted it. – kos Aug 24 '15 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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