How to auto pass password in shell script !


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to auto pass password in shell script !
# 1  
Old 09-26-2012
Question How to auto pass password in shell script !

Hi all,

I have a simple script to check the CPU, Swap Memory and Hard Disk. But I can auto assign password in the script to automatic run it in crontab.

Quote:
#! /bin/bash

# Total memory space details

echo "Memory Space Details"
free -t -m | grep "Total" | awk '{ print "Total Memory space : "$2 " MB";}'
free -t -m | grep "Total" | awk '{ print "Memory Usage space : "$3 " MB";}'
total_mem=$(free -t -m | grep "Total" | awk '{ print $2 }')
mem_used=$(free -t -m | grep "Total" | awk '{ print $3 }')
percent1=$((($mem_used*100)/$total_mem))

echo "Memory Usage : $percent1%"


free -t -m | grep "Swap" | awk '{ print "Total Swap space : "$2 " MB";
print "Used Swap Space : "$3" MB";
print "Free Swap : "$4" MB";
}'
Everytime when I run this script, it require to insert password like the message below :

Quote:
test:~ # ssh root@192.168.1.1 'bash -s' < /home/scripts/memLinux.sh
root@192.168.1.1's password: xxxx
Memory Space Details
Total Memory space : 65207 MB
Memory Usage space : 31438 MB
Memory Usage : 48%
Total Swap space : 32773 MB
Used Swap Space : 2161 MB
Free Swap : 30611 MB
How can I solve this problem ?

Last edited by cafecoc85; 09-26-2012 at 04:47 AM.. Reason: Modify the quote
# 2  
Old 09-26-2012
It's not the script, it's ssh asking for a password.

Search "ssh without password" in Google to properly configure ssh client and server.

However IMHO ssh-ing as root is truly bad. IMHO you should ssh as normal user (and without password), and then, once logged in the remote system, become root - yes, inserting the root password - if you need it.

BTW: in most systems your script commands don't need root privileges.
--
Bye
# 3  
Old 09-26-2012
Quote:
Originally Posted by Lem
It's not the script, it's ssh asking for a password.

Search "ssh without password" in Google to properly configure ssh client and server.

However IMHO ssh-ing as root is truly bad. IMHO you should ssh as normal user (and without password), and then, once logged in the remote system, become root - yes, inserting the root password - if you need it.

BTW: in most systems your script commands don't need root privileges.
--
Bye
Thank you for mention me about not using root user to execute this script. It just test script, so I don't care too much about it. I will google it !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass the password to su in shell script

Hello, I am using below command but this is asking for tty c42dba {/home/oracle}: echo sersnp | su -c ggs standard in must be a tty Best regards, Vishal (4 Replies)
Discussion started by: admin_db
4 Replies

2. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

5. Shell Programming and Scripting

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (14 Replies)
Discussion started by: thisissouvik
14 Replies

6. AIX

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (2 Replies)
Discussion started by: thisissouvik
2 Replies

7. Shell Programming and Scripting

Auto Script to Access external Server via SFTP using Password and Key

Hello All, I am stuck! I have access to an external server via SFTP. In order to access the external server I was given a specific port, password, and a ppk. I would to create a script on my server end that can I can setup as a corn job, that will connect to the external server and... (1 Reply)
Discussion started by: kingr008
1 Replies

8. Shell Programming and Scripting

How to pass decrypted password to script

Hi Everybody, I am trying to write a script (ksh) to connect to oracle db via sqlplus. As I do not want the password to be in plain text, I've tried to use java to encrypt and decrypt it but I am not sure how can I pass the decrypted password to the script. Pls advise. Below is what I would... (1 Reply)
Discussion started by: Nick1971
1 Replies

9. Shell Programming and Scripting

Pass root password through script

I have several clients (over 120) connected to my server. I want to push some patch to all the client using a script which copies the file from the server to a specific path on the client and then installs it. But for installation of the patch, it needs to be done thorough root login on client.... (7 Replies)
Discussion started by: shahdeo
7 Replies

10. Shell Programming and Scripting

Read Oracle Username password SID from single file and pass it to shell

Dear All I am trying to write one shell which will be running through Cron which contain one SQL query. But I want to draw/fetch the Username password and Instance name (required to loging to the database) from one single file to run that SQL query . Also this file contain details of multiple... (2 Replies)
Discussion started by: jhon
2 Replies
Login or Register to Ask a Question