The goal is to change some parameters on a lot of devices on connections that are kind of unreliable (wireless)--according to csv that has the format: IP,Parameter,Parameter
I would like to make a bash script that uploads a file, then checks the contents of it against the local copy, then run other commands using only bash, ssh, cat, and diff on the remote end. Only basic tools are available on the remote linux servers (Busybox), and there are thousands of them, so scaling is important. I would very much prefer to do all of this in a single SSH session, where authentication only has to happen one way, and one time. Pretend for the moment that security is not an issue. I am looking into how to scale rsa public key distribution to all of these, but for now, I want this to work with password authentication. Please don't make this into a banter about security practices. Perhaps there is a much easier way to accomplish the goal mentioned above. If so, please share. Thanks.
So the steps are:
- Log into the remote box.
- Copy the local file to the remote box in a specific directory.
- Run diff, or some type of check for file copy errors.
- If error, stop script, otherwise continue.
- Run other commands on remote box.
- Output the results of the commands to a local file.
- Close the session.
- Rinse and repeat.
Below is sort of pseudocode. But it gives you an idea of what I am trying to do. diff does not see the output of cataloging the local file, so it thinks they are not the same.
IFS=\, while read IP PARAM1 PARAM2; do cat /home/user/uploadscript.sh | sshpass -p $password ssh -v -o StrictHostKeyChecking=no -l uname 192.168.x.x 'cat > /tmp/script.sh && cat | diff -sb - /tmp/script.sh && IP="IP" && P1="$PARAM1" && P2="$PARAM2" && ./script.sh' done < list_of_ipaddresses.txt >> log.txt