Shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell scripting
# 1  
Old 09-17-2010
Shell scripting

Hi All,
I am not able to see the output of $1 variable as I am passing in below script:--

Code:
#!/bin/bash -xv
echo "Enter ur password"
+ echo 'Enter ur password'
Enter ur password
read pw
+ read pw
dbaguest
echo "Enter username"
+ echo 'Enter username'
Enter username
read usrnm
+ read usrnm
password
echo "enter ip addr"
+ echo 'enter ip addr'
enter ip addr
read ip
+ read ip
192.168.12.1
while [ $# -ne 0 ]
do
echo $1
shift
done
+ '[' 0 -ne 0 ']'
echo "logging in to the server"
+ echo 'logging in to the server'
logging in to the server
ssh $2/$1@$3
+ ssh /@
ssh: : host/servname not known
echo "success"
+ echo success
success
exit 0
+ exit 0

Please suggest me some way out.

Regards,
Manish

Moderator's Comments:
Mod Comment Please start using code tags, and a more descriptive subject title

Last edited by Scott; 09-17-2010 at 05:01 AM..
# 2  
Old 09-17-2010
Because $1,$2 and $3 contains nothing in your case.
these the special variable used when you pass values as the command line arguments while executing script. and I guess you are not passing anything instead expecting from user to type the username, passwd and hostname.


when you reading the values these are automatically defined the the variable which you are passing in the read ( usrnm, pw and ip ) in your case.

so try replacing $1,$2 and $3 with $pw, $usrnm and $ip respectively.

Code:
#!/bin/bash -xv

echo "Enter ur password"
read pw
echo "Enter username"
read usrnm
echo "enter ip addr"
read ip
echo "logging in to the server"
ssh ${usrnm}/${pw}@${ip}
echo "success"
exit 0

# 3  
Old 09-17-2010
use the variables that you use for reading $pw, $usrnm, $ip...and not $1, $2 and $3...
# 4  
Old 09-17-2010
See below ....
Code:
#!/bin/bash -xv
echo "Enter ur password"
+ echo 'Enter ur password'
Enter ur password
read pw
+ read pw
dbaguest
echo "Enter username"
+ echo 'Enter username'
Enter username
read usrnm
+ read usrnm
password
echo "enter ip addr"
+ echo 'enter ip addr'
enter ip addr
read ip
+ read ip
192.168.12.1
while [ $# -ne 0 ]
do
echo $pw
shift
done
+ '[' 0 -ne 0 ']'
echo "logging in to the server"
+ echo 'logging in to the server'
logging in to the server
ssh $usrn/$pw@$ip
+ ssh /@
ssh: : host/servname not known
echo "success"
+ echo success
success
exit 0
+ exit 0

# 5  
Old 09-17-2010
Why don't you just paste the script content ?
# 6  
Old 09-20-2010
script is not working as expected.

Hi ,
Below script is not working as expected.It is timing out while it is trying to log to the server using ssh.Password is correct but I am not sure how password is going to be sent using expect module.Please let me know if any syntax error is there in my script.

Code:
#!/bin/bash -xv
username="dbaguest"
echo  "Enter your password:"
read  newPassword
cat ssh.csv | while read line;
do
username=`echo $line | cut -d, -f1`
addr=`echo $line | cut -d, -f2`
paswd=`echo $line | cut -d, -f3`
echo "$username,$addr,$paswd"
cct=$(./test.exp $paswd $newPassword $addr $username)
if [[ "$cct" == *login* ]]; then
echo "SSH Connection to $host succeeded" >> testlog
if [[ "$cct" == *successfully* ]]; then
echo "Password has been changed successfully for $host" >> testlog
else
echo "Password change failed for $host." >> testlog
echo "$host,$addr,$paswd" >> errorlog
fi
else [[ "$cct" == *Permission* ]]
echo "$host,$addr,$paswd" >> errorlog
fi
cct=""
done

==============================
test.exp:--
Code:
#!/usr/local/bin/expect -f --
set currentpasword [lrange $argv 0 0]
set newpassword [lrange $argv 1 1]
set ipaddr [lrange $argv 2 2]
set username [lrange $argv 3 3]
set cmd "passwd"
spawn  ssh -t $username@$ipaddr
expect  "Enter password for key:"
send "yes\r"
expect "*password*"
send "$currentpasword\r"
expect "$"
expect "Last login:" {
send "$cmd\r"
expect "$"
expect "*(current) UNIX password*"
send "$currentpasword\r"
expect "*New UNIX Password*"
send "$newpassword\r"
expect "*Retype*"
send "$newpassword\r"
expect "$"
expect "exit\r"
}

Regards

Last edited by pludi; 09-20-2010 at 08:08 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

2. Shell Programming and Scripting

help me in Shell Scripting

Hi there please have a look at the code..i want to create Using a named pipe. Run a find in the background starting in the working directory While this is happening wait for input from the user to ask him which file to find. If the user does not enter any data in 10 seconds ask the user again.... (1 Reply)
Discussion started by: kattak1511
1 Replies

3. Shell Programming and Scripting

Shell scripting

Hi, if in a network there are lots of PCs connected with either windows or linux as operating system.Then what will be the shell script for the same and also if the PC has linux in it then we have to find if it is occupied or unoccupied. If the PC has windows in it then we have to find if it is... (6 Replies)
Discussion started by: akansha singh
6 Replies

4. UNIX for Dummies Questions & Answers

Shell Scripting

Hey I have a data in the file named as outputFile.txt. The data is in the format 123456,12345678912345,400,09/09/09,INACTIVE. I want this output without commas ie 12345612345678912345400090909INACTIVE. Please tell me what to do and clear explain all the terms, as I am new to it. (6 Replies)
Discussion started by: sampandey31
6 Replies

5. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

6. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

7. Android

Android Scripting Environment: Shell Scripting and Android

I just upgraded to Android 2.2 from 2.1. The GPS issue that was troublesome in 2.1 seems to have been fixed. Some of web browsing seems faster, but it could just be my connection is better today ;) Flash works in some browsers but not very good and it is too slow for Flash apps designed for... (0 Replies)
Discussion started by: Neo
0 Replies

8. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

9. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question