Reputation: 2801
I want to run a set of commands on start of my machine which requires password input as well to connect to other machine on local network.
My Commands:
1) ssh userName@IPADDRESS
2) cd /var/www/html
3) cd Proj name
First command requires password on execution.
OS Version: Ubuntu 16.04 LTS
I have tried various script but none was useful for connecting in other machine.
Thanks in advance.
Upvotes: 0
Views: 94
Reputation: 81
Try this,
Put the command in your crontab file. Make sure to edit the cron job for the root user, Command is sudo crontab -e.
@reboot yourscript.
Put a yourscript under the /etc/init.d directory, Change the yourscript permissions(to make it executable) of the script.
Upvotes: 1
Reputation: 100
Already tried this?
#!/usr/bin/expect -f
spawn ssh user@hostname
expect "password:"
sleep 1
send "<your password>\r"
command1
command2
and do you want that this script auto runs on your PC or on the Server?
However:
- If you want that it starts on your PC when the Server starts, then write a script that checks every minute if the server runs, and when the server runs execute that code above.
- you want that the script runs on the machine at startup, just use crontab.
- you want that it runs on your PC at your PC's startup, just use crontab.
Upvotes: 2