I have about 3000 individual commands that I need to execute on a system via Putty. I am doing this by copying ~100 of the commands and pasting them into a putty SSH session. It works, however the issue is that Putty does not process them serially and the output gets garbled.
Is there a way to make Putty process each command, wait for a return and then process the next? The Windows command prompt does this and I'm thinking there is a way to do so with Putty.
Yes, I know I could put this in a bash script, but due to circumstance outside my control, this has to be done using SSH and in a manner that can be monitored as we go and logged.
I do this all the time. Put your commands in a (
)
block, which will run it as a subshell, perfectly everything within serially. I'm running Windows PuTTY and connecting to Linux and AIX servers. Try it.
(
Command1
Command2
Command3
)
In practice, I might have a huge load of many 100s of statements I want to run, in Notepad++ or whatever. So I copy them to clipboard, and then in PuTTY:
(
paste in your wad here
)
EDIT: If you want to log the output from each of your statements individually, you might do something like this:
(
Command1 > /home/jon/command1output.txt
Command2 > /home/jon/command2output.txt
Command3 > /home/jon/command3output.txt
)
or if you just want one big stream of output, you could interleave separators for easier reading later:
(
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "[`date`] Now running Command1 ..."
Command1
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "[`date`] Now running Command2 ..."
Command2
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "[`date`] Now running Command3 ..."
Command3
)
EDIT2: Another variation using an inline function. All paste-able into PuTTY, with perfect serial running, logging as command1:output1,command2:output2,... , and capable of driving SQL*Plus.
(
function geniusMagic() {
echo " "
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
date
echo "RUNNING COMMAND:"
echo " "
echo "$*"
echo " "
echo "OUTPUT:"
echo " "
sh -c "$*"
}
geniusMagic df -m /home
geniusMagic 'printf $RANDOM | sed "s/0//g"'
geniusMagic 'echo "select count(*)
FROM all_tables;
" | sqlplus -s scott/tiger'
)
Sample output:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wed Jun 25 17:41:19 EDT 2014
RUNNING COMMAND:
df -m /home
OUTPUT:
Filesystem MB blocks Free %Used Iused %Iused Mounted on
/dev/hd1 1024.00 508.49 51% 3164 3% /home
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wed Jun 25 17:41:19 EDT 2014
RUNNING COMMAND:
printf $RANDOM | sed "s/0//g"
OUTPUT:
2767
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wed Jun 25 17:41:19 EDT 2014
RUNNING COMMAND:
echo "select count(*)
FROM all_tables;
" | sqlplus -s scott/tiger
OUTPUT:
COUNT(*)
----------
48
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With