Hello,
Can you help me ?
$7 fits to remote server.
I can launch the script from local or remote server.
I would like my_script.sh to choose local or remote command depending the variable $7.
Is the function f1 right or wrong ? In this moment, i can't test it.
Thanks in advance.
I create the input file
vi my_inputfile
# comment 1
# comment 2
$1 $2 $3 $4 $5 $6 $7
./my_script my_inputfile
vi my_script
#!/bin/bash
# set -vx
f1() {
server=$(hostname -s)
if [ $server = $6 ]; then
echo $1 $2 $3 $4 $5 $6
else
ssh -n $6 'echo $1 $2 $3 $4 $5 $6'
}
case $# in
0) echo -e "# comment1\n# comment2" > list_file
read -p "Please fill in this list_file: "
echo $REPLY
;;
1) if [ ! -f "$1" ]
then > $1 && echo -e "# comment1\n# comment2" > $1
read -p "Please fill in "$1": "
echo $REPLY
else
if [ -f "$1" -a $(grep -v '^#' "$1" | wc -l ) -ne 0 ]
then
grep -v '^#' "$1" |
while read arg1 arg2 arg3 arg4 arg5 arg6 arg7
do f1 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7
done
else
read -p "Please fill in $1 : "
echo $REPLY
fi
fi
;;
4) echo -e "# comment1\n# comment2" > list_file
echo $1 $2 $3 $4 >> list_file
;;
5) echo -e "# comment1\n# comment2" > $1
f1 $2 $3 $4 $5 $6 >> "$1"
;;
6) echo -e "# comment1\n# comment2" > $1
f1 $2 $3 $4 $5 $6 $7 >> "$1"
;;
*) echo "error msg"; exit
esac