F
F
frizesb2018-11-23 12:00:24
bash
frizesb, 2018-11-23 12:00:24

How can I make sure that in a bash script, when using sshpass, subsequent commands are executed using a password?

How to make it so that in a bash script when using sshpass, subsequent commands are executed using a password
here is the main script file

#!/bin/bash
#debug script #username
username
=$(cat /home/administrator/crontab/usr)
#password file
password=$(cat /home/administrator/crontab/pass)
#name of hosts to process
hostnames= "
vld-prod1-03
"
# log file
log="/home/administrator/crontab/222.txt" log2
="/home/administrator/crontab/fulllog.txt"
# change hostnames to H in
for H in $hostnames
do
if
if
# copy files from our PC to a remote host for further execution
sshpass -p "$password" scp -r -o StrictHostKeyChecking=no /home/administrator/crontab [email protected]$H:/home/administrator
then
echo "scp SUCCESS"
else
echo "scp FAIL"
fi
if
# connect to another host
sshpass -p "$password" ssh -o StrictHostKeyChecking=no [email protected]$H "`cat /home/administrator/crontab/2`"
then
echo "ssh SUCCESS"
else
echo "ssh FAIL"
fi
then
echo "$H - Success" >> $log
else
echo "$H - Runtime Error" >> $log
fi
sleep 2
done

here is the second file with commands
#!/bin/bash
password=$(cat /home/administrator/crontab/pass)
for P in $password
do
if
sudo mkdir /home/user/.cron
then
echo "OK"
else
exit
fi
if
cp -f -rp /home/administrator/crontab/crontab/del.sh /home/user/.cron
then
echo "OK"
else
exit
fi
if
crontab -u user /home/administrator/crontab/crontab/reg
then
echo "OK"
else
exit
fi
if
m -rf /home/administrator/crontab
then
echo "OK"
else
exit
fi
exit
done

Tell me what I'm doing wrong and how to implement

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chupasaurus, 2018-11-23
@chupasaurus

Use Ansible, Luke.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question