LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Logging in and logging out of a server in a script (http://www.linuxquestions.org/questions/linux-newbie-8/logging-in-and-logging-out-of-a-server-in-a-script-523129/)

frankie_DJ 01-26-2007 08:40 PM

Logging in and logging out of a server in a script
 
Hi everyone,

I would like to be able to:
login to an execution node from a headnode of a cluster
have my job done there
logout back to the head node
scp output file to some storage server
repeat the proces in a loop

The problem is, if I put a 'logout' command in a script, I get an error "not a login shell, use 'exit'". If I use 'exit' then this command is interpreted by the shell as exiting the loop and stopping the execution of the script. Is there a way around this?
Maybe using trap to trap a signal or something? I am out of options
- my bash scripting skills are not very refined.

Thanks.

Tinkster 01-26-2007 11:05 PM

Code:

for i in true;
do
  ssh user@node -C "command; command2; ... " >> node.out 2>&1
done

No need to log-in and out, all very tidy.


Cheers,
Tink

frankie_DJ 01-27-2007 07:00 PM

Tinkster,

Thanks for the reply. No disrespect, but your suggestion kinda screwed me over. Putting my commands in the quotations deleted all my data files. Fortunately I backed them up beforehand. I ended up using your suggestion for the quotes (thanks for that), but I put all the stuff from inside the quotes in another script and run it that way. It worked.

I have no idea how did I manage to erase everything, and actually, I'd appreciate if someone could explain to me what went wrong.

This is what happened: I have 20 directories called
anneal_1 to anneal_20. Each one has different number of data files called si.001 to si.0** (stars are some nubers). I needed to pick up an si.0** file (from each anneal_* directory) that has the highest number in its name, and then execute simulation on that file. So this is the beginning of the unsuccesfull script - the part that messed me up:

Code:

for i in `seq 1 20`
do
  rsh node10 "
  cd /to/the/appropriate/directory
  max=anneal_$i/si.001
  for j in anneal_$i/si.0*
  do
        if [ $j > $max ]
        then
                max=$j
        fi
  done
  ... " #rest of the simulation run on the node10

I get the error message
Code:

bash: line 8: [: missing `]'
twenty times. After that, all the files si.0** were empty except for the highest-numbered one, and get this: an empty file with the name " ] " showed up in the directory where script is executed (!?!?). How that happened is a great mistery to me :scratch: . Some weird redirection was done by the '>' character. Actually, without the quotation marks that I use to submit job to the execution node, it works as it's supposed to.

Tinkster 01-27-2007 10:50 PM

Sorry about your loss of data ... I never said I knew what
you're doing, and that my approach was safe for that.

What is your users default shell on the remote node?


Cheers,
Tink

frankie_DJ 01-28-2007 12:03 AM

it's bash, version 3.00. I don't know if I made it clear, but,
when I regularly log in the exec. node and run this script bit, it works fine.


All times are GMT -5. The time now is 10:07 PM.