How to use ssh in SHELL SCRIPT. You can use sshpass command to use
ssh in shell script. Below is the syntax to find the mounted partition
details of the remote server from local machine.
sshpass -p 'Mute4@sec' ssh saikrishna.b@xxserver.com df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 40631988 22265072 16269632 58% /
/dev/sda5 2030736 456452 1469464 24% /tmp
/dev/mapper/VolGroup00-data
225522932 191902676 21979424 90% /data
/dev/sda1 194442 17793 166610 10% /boot
tmpfs 16470432 0 16470432 0% /dev/shm
[root@test ~]# cat test.txt
Mute4@sec
With out showing the password you can store the password in a file and call them . Here -f denotes file and test.txt is the file where the password has been stored.
[root@test1 ~]# sshpass -ftest.txt ssh saikrishna.b@xxxserver.com df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 40631988 22265120 16269584 58% /
/dev/sda5 2030736 456452 1469464 24% /tmp
/dev/mapper/VolGroup00-data
225522932 191905108 21976992 90% /data
/dev/sda1 194442 17793 166610 10% /boot
tmpfs 16470432 0 16470432 0% /dev/shm
[root@test1 ~]# sshpass -ftest.txt ssh saikrishna.b@xxxx.com "df -Th"
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext3 39G 22G 16G 58% /
/dev/sda5 ext3 2.0G 446M 1.5G 24% /tmp
/dev/mapper/VolGroup00-data
ext3 216G 184G 21G 90% /data
/dev/sda1 ext3 190M 18M 163M 10% /boot
tmpfs tmpfs 16G 0 16G 0% /dev/shm
sshpass -p 'Mute4@sec' ssh saikrishna.b@xxserver.com df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 40631988 22265072 16269632 58% /
/dev/sda5 2030736 456452 1469464 24% /tmp
/dev/mapper/VolGroup00-data
225522932 191902676 21979424 90% /data
/dev/sda1 194442 17793 166610 10% /boot
tmpfs 16470432 0 16470432 0% /dev/shm
[root@test ~]# cat test.txt
Mute4@sec
With out showing the password you can store the password in a file and call them . Here -f denotes file and test.txt is the file where the password has been stored.
[root@test1 ~]# sshpass -ftest.txt ssh saikrishna.b@xxxserver.com df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 40631988 22265120 16269584 58% /
/dev/sda5 2030736 456452 1469464 24% /tmp
/dev/mapper/VolGroup00-data
225522932 191905108 21976992 90% /data
/dev/sda1 194442 17793 166610 10% /boot
tmpfs 16470432 0 16470432 0% /dev/shm
[root@test1 ~]# sshpass -ftest.txt ssh saikrishna.b@xxxx.com "df -Th"
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext3 39G 22G 16G 58% /
/dev/sda5 ext3 2.0G 446M 1.5G 24% /tmp
/dev/mapper/VolGroup00-data
ext3 216G 184G 21G 90% /data
/dev/sda1 ext3 190M 18M 163M 10% /boot
tmpfs tmpfs 16G 0 16G 0% /dev/shm
No comments:
Post a Comment