Reputation: 8975
When I get a new VPS there is always the same tasks that I need to do before I can begin using the VPS.
I need to change the root password. Add more repositories. Install some programs with apt-get
Would it be possible to create a simple script to do all these things? What type of script would I need to write?
Upvotes: 1
Views: 433
Reputation: 5972
yes... it is possible:
#!/bin/bash
script=$'
apt-get install <package-name>
apt-get install <package-name>
apt-get install <package-name>
passwd <<EOF
<your-new-password>
<your-new-password>
EOF
'
while read pass port user ip; do
sshpass -p$pass ssh -o 'StrictHostKeyChecking no' -p $port $user@$ip "$Script"
done <<___HERE
<pass> <port> <user> <ip>
<pass> <port> <user> <ip>
. . . .
<pass> <port> <user> <ip>
___HERE
first of all this makes a ssh connection to your ip. after that run commands in $script
and then go to your next server.
but on all of your servers you should install sshpass
:
apt-get install sshpass
Upvotes: 0
Reputation: 13065
You can write a simple bash script, or you can look into power tools like Puppet, Chef, Salt or Ansible.
Scripts are very low-level, and hard to make "idempotent" (able to be run twice). The above tools let you declare what you want, and the the tools implement it, skipping over work that has already been done.
Upvotes: 1
Reputation: 328
What your looking for is a bash script. Shell scripting using bash is a great way to automate all of those menial tasks that you run one-by-one from the command line
Check it: http://www.panix.com/~elflord/unix/bash-tute.html
Upvotes: 0