0

I'm trying to write a script that builds a list of nodes then ssh into the first node of that list and runs a checknodes.sh script which it's self is just a for i loop that calls checknode.sh

The first 2 lines seems to work ok, the list builds successfully, but then I get either get just the echo line of checknodes.sh to print out or an error saying cat: gpcnodes.txt: No such file or directory

MYSCRIPT.sh:

#gets the master node for the job
MASTERNODE=`qstat -t -u \* | grep $1 | awk '{print$8}' | cut -d'@' -f 2 | cut -d'.' -f 1 | sed -e 's/$/.com/' | head -n 1`
#builds list of nodes in job
ssh -qt $MASTERNODE "qstat -t -u \* | grep $1 | awk '{print$8}' | cut -d'@' -f 2 | cut -d'.' -f 1 | sed -e 's/$/.com/'  > /users/issues/slow_job_starts/gpcnodes.txt"

ssh -qt $MASTERNODE cd /users/issues/slow_job_starts/
ssh -qt $MASTERNODE /users/issues/slow_job_starts/checknodes.sh

checknodes.sh

for i in `cat gpcnodes.txt `
do 
    echo "### $i ###"
    ssh -qt $i /users/issues/slow_job_starts/checknode.sh
done

checknode.sh

str=`hostname`
cd /tmp
time perf record qhost >/dev/null 2>&1 | sed -e 's/^/${str}/'
perf report  --pretty=raw | grep % | head -20 | grep -c kernel.kallsyms | sed -e "s/^/`hostname`:/"
1
  • You should search for Paramiko... it will make SSHing between various machines/running remote commands a breeze Commented May 9, 2020 at 22:18

1 Answer 1

1

When ssh -qt $MASTERNODE cd /users/issues/slow_job_starts/ is finished, the changed directory is lost. With the backquotes replaced by $(..) (not an error here, but get used to it), the script would be something like

for i in $(cat /users/issues/slow_job_starts/gpcnodes.txt)
do 
    echo "### $i ###"
    ssh -nqt $i /users/issues/slow_job_starts/checknode.sh
done

or better

while read -r i; do 
    echo "### $i ###"
    ssh -nqt $i /users/issues/slow_job_starts/checknode.sh
done < /users/issues/slow_job_starts/gpcnodes.txt

Perhaps you would also like to change your last script (start with cd /users/issues/slow_job_starts)

You will find more problems, like sed -e 's/^/${str}/' (the ${str} inside single quotes won't be replaced by a host), but this should get you started.

EDIT:
I added option -n to the ssh call.
Redirects stdin from /dev/null (actually, prevents reading from stdin).
Without this option only one node is checked.

Sign up to request clarification or add additional context in comments.

2 Comments

afaik ssh eats/slurps stdin (this is what I remember from my ssh scripts) , a work around is to use a different fd.
@Jetchisel Thanks, I added the option -n.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.