How do I run a series of UNIX commands in batch file without terminating session? -


i have implemented automation through batch file login remote server , run series of commands therin. batch file contents follows:

@echo off echo 1 -^> connect 2 server echo 2 -^> quit set /p id=enter choice :   if "%id%"=="1" start "" c:\work\putty.exe -load sessionname -l username -pw password -m cmd.txt if "%id%"=="2" exit 

my cmd.txt file contains following commands:

su superuser password ssh server password su myid password 

the batch connects server; fails retain session. tweak appreciated.

for own use verified -m switch putty

the -m option performs similar function ‘remote command’ box in ssh panel of putty configuration box (see section 4.18.1). however, -m option expects given local file name, , read command file.

with servers (particularly unix systems), can put multiple lines in file , execute more 1 command in sequence, or whole shell script; arguably abuse, , cannot expected work on servers. in particular, known not work ‘embedded’ servers, such cisco routers.

roughly guessed. think what's happening commands might running ok, terminates session when done (which default behaviour ssh [command] on unix. around try running 'bash' @ end start terminal user, should stay running until exit. if doesn't work try running 'sleep 10' see if session stays running longer - should verify that's problem we're dealing with.

much stackoverflow demands strictly answer question, hope i've provided above. feel in case remiss not flag serious security concerns i'd have on you're doing. maintain shouldn't answer question doing securely (with ssh , root passwords involved) without covering potential security pitfalls.

what you're doing seems bad idea because:

  • it makes file 2 unencrypted root-capable passwords finds file
  • this script giving you root access default, isn't safe way operate. ever accidentally type rm -r in wrong window?
  • also, messing second hop (by say, replacing ssh server script run ssh log passwords) password third hop root privileges.
  • ssh keys should away using passwords log on. use them.
  • ssh port forwarding lets skip sshing second hop - instead tunnel through (i'm guessing third box isn't internet accessible), again using ssh keys lets skip passwords.
  • the first 'su superuser' shouldn't necessary unless permissions don't allow ssh (does ssh_allow group exist on box?), might problem should fix - not being member of group allowed use ssh.

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -