1. Create rsa id
> cd
> ssh-keygen -t rsa
2. Copy rsa id to remote computer as user me
> ssh-copy-id -i ~/.ssh/id_rsa.pub me@10.19.169.5
3. Test by
> ssh me@10.19.169.5
The computer at 10.19.169.5 shall NOT ask you for password
This blog is created to keep things which I always need to remember in Python and Linux scripting. ... and few other things.
Wednesday, February 24, 2010
Shell script to execute command on the list of computers
The list of computers is given as a text list of IP adresses named "all.list". Each IP in saparate line
To execute commands on each computer create file all.sh with following text
for i in `cat all.list | awk '{ print $i}'` ; do echo $i; ssh $i $1 ; done
Execute commands by
> source ./all.sh "ls -la"
To execute commands on each computer create file all.sh with following text
for i in `cat all.list | awk '{ print $i}'` ; do echo $i; ssh $i $1 ; done
Execute commands by
> source ./all.sh "ls -la"
To execute command as root on remote computer with ip 10.19.148.65 using ssh
To execute command as root on remote computer with ip 10.19.168.65
> ssh root@10.19.148.65 "ls -la"
To execute text replacement on remote computer using perl script
> ssh root@10.19.148.65 "perl -p -e 's/oldtext/newtext/g' oldfile >newfile"
> ssh root@10.19.148.65 "ls -la"
To execute text replacement on remote computer using perl script
> ssh root@10.19.148.65 "perl -p -e 's/oldtext/newtext/g' oldfile >newfile"
How to replace text in many files using single perl command
To replace text "localhost" to "localnet" in all files with extension text execute following
> perl -p -e "s/localhost/localnet/g" *.txt
To add new line after new text "localnet" use new line code \x0a
> perl -p -e "s/localhost/localnet\x0anew line/g" *.txt
To insert TAB in replaced text use code \x09
> perl -p -e "s/localhost/localnet\x0anew line\x09rest of line after tab/g" *.txt
> perl -p -e "s/localhost/localnet/g" *.txt
To add new line after new text "localnet" use new line code \x0a
> perl -p -e "s/localhost/localnet\x0anew line/g" *.txt
To insert TAB in replaced text use code \x09
> perl -p -e "s/localhost/localnet\x0anew line\x09rest of line after tab/g" *.txt
Subscribe to:
Posts (Atom)
Followers
About Me
- Krzysztof Pakuła
- Znak zodiaku - Lew