Hope you are all well. New to scripting, and all those characters are all a new language for me. Though hoping to get my little head round it all sooner or later.
I was wondering whether anyone could help with a script template example.
What I would like to happen is to run the script and for it to respond with whatever file I would like the script to check and then perform an md5sum check on it and then print out the results.
The thing is, that all hosts are on the same LAN but requires ssh into it.
Would appreciate any help given so I can start to get my head round this scripting marlakey.
Thanks in advance.
---------- Post updated at 11:05 AM ---------- Previous update was at 11:03 AM ----------
Thanks for the input guys, really appreciate it. I will try this out on my test system and let you know the outcome. Hope it all goes well.
Again, thank you.
---------- Post updated at 04:37 AM ---------- Previous update was at 03:41 AM ----------
WOW, thanks, just tested it and it's just what I needed.
I maybe pushing the boat out a little bit further, what should I put in the file if I wanted an option to use all the servers in the server list as well as currently inputting one server at a time.
Thank you though guys. You really helped me out here.
I've noticed that the output is shown twice and a message is given, is there a reason why that is:
#? 1
96fbd1ef56e61e8455f356614516b829 /opt/xxx/lib/libhta.so
96fbd1ef56e61e8455f356614516b829 /opt/xxx/lib/libhta.so
/usr/bin/md5sum: server02: No such file or directory
This gives you a new menu item "All the above" (changes in green).
#!/bin/bash
(( $# < 1 )) && {
printf "usage: %s <file_name>\n" "${0##*/}"
exit 1
}
_server_list=( server1 server2 )
_fn=$1
_cmd=/usr/bin/md5sum
function dossh
{
ssh "$1" "
[ -f \"$_fn\" ] &&
$_cmd $_fn ||
printf \"error executing %s %s on %s\n\" \\
\"$_cmd\" \"$_fn\" \"$1\""
}
select s in "${_server_list[@]}" "All the above" "quit"; do
if [[ -z "$s" ]]
then
echo "Option $REPLY is invalid - Please select a number from 1 to $(( ${#_server_list[@]} + 2))"
else
[[ "$s" = "quit" ]] && break
if [[ "$s" == All* ]]
then
for s in "${_server_list[@]}"
do
dossh $s
done
continue
fi
dossh $s
fi
done