#!/bin/sh argn=$# i=0 for arg do shift i=$(( i + 1 )) if [ "$i" -lt "$argn" ]; then set -- "$@" ssh -t "$arg" else set -- "$@" "/pathtofile/$arg/log.log" fi done command "$@"
Here is what the above code is Doing:
1. It takes the arguments passed to the script and stores them in the variable argn.
2. It then loops through the arguments and shifts them to the left.
3. It then checks if the current argument is the last one. If it is, it appends the path to the log file to the end of the argument list.
4. If it is not the last argument, it appends the ssh command to the argument list.
5. Finally, it executes the command.
The above script can be executed as follows:
$ ./script.sh host1 host2 host3