-   Linux - Newbie (
-   -   Logging in and logging out of a server in a script (

frankie_DJ 01-26-2007 07: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.


Tinkster 01-26-2007 10:05 PM


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

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


frankie_DJ 01-27-2007 06:00 PM


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:


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

I get the error message

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 09: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?


frankie_DJ 01-27-2007 11:03 PM

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 06:42 AM.