Script to scp every minute with plain password


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to scp every minute with plain password
# 1  
Old 05-20-2017
Script to scp every minute with plain password

Hello,

I have a Solaris x86 server. I am installing patch cluster on that. Out of so many patches, any one patch is breaking its LDAP authentication and I am not able to figure out, which one is that. I have restored server and planning to apply that patch cluster again.
To figure that patch, I got an idea. While patching is running, I would want to setup a cronjob in server2, which will run a scp job to copy something with my user-id (non-root), to this server, with time-stamp.

I need the script, which can be setup in cronjob of server2 and that will pull a file with scp with my user-id and LDAP password, with time-stamp. I would want to run it every minute. After patching, I will check time-stamp, when that scp was broke and I will check in logs, which patch was applied at that time.

I tried taking help of expect with below script
Code:
#!/usr/local/bin/expect -f
# ----------------------------------------------------------------------
# For example:
#  ./sshlogin hostname username password who
#  ./sshlogin hostname username password uname -a
# ----------------------------------------------------------------------
# set Variables
set hostname [lrange $argv 0 0]
set username [lrange $argv 1 1]
set password [lrange $argv 2 2]
set scriptname [lrange $argv 3 3]
set arg1 [lrange $argv 4 4]
set timeout 20
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh -q -o NumberOfPasswordPrompts=1 -o StrictHostKeyChecking=no $username@$hostname $scriptname $arg1
match_max 100000
# Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof
catch wait reason
set exit_status [lindex $reason 3]
send_user "EXIT CODE: $exit_status\r"
exit $exit_status

But it doesn't give me expected value and ends up with some numeric ouput
Code:
bash-3.2# /var/tmp/ssh-test.sh nproc-db34-admin broe ZAQ!2wsx uname -a
/var/tmp/ssh-test.sh nproc-db34-admin broe ZAQuptimewsx uname -a
spawn ssh -q -o NumberOfPasswordPrompts=1 -o StrictHostKeyChecking=no broe@nproc-db34-admin uname -a
Password:
bash-3.2#  255

Assuming, it is not liking format of my password, with ! mark and numeric 2
Code:
bash-3.2# !2
uptime
  3:02pm  up 1 day(s),  1:42,  1 user,  load average: 0.01, 0.02, 0.02
bash-3.2#

Regards
----------------------------
I changed the shell to ksh and then it worked, so consider this thread as solved.

Last edited by ron323232; 05-20-2017 at 07:19 PM.. Reason: Solved
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

scp without password

Hello experts, OS : CentOS Could you please help me with the following scenario : I wish to use scp command in order to copy a file (say : f1.txt) from server 2 to server 1. Both servers have a common user (say : user1) configured. Also, the file is owned by the same user on both... (2 Replies)
Discussion started by: H squared
2 Replies

2. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

3. Shell Programming and Scripting

Script should wait for password while doing scp

Hi team, need help on this :- trying to scp a file from A ( it could any server among hundreds not one) server to B server ( fixed ) . The script runs in a third server CFGEngine server. a. we dont use static password ( its pin + rsa token) so , "here documents" kind of thing is not... (3 Replies)
Discussion started by: gauravsharma29
3 Replies

4. Shell Programming and Scripting

Take minute per minute from a log awk

Hi, I've been trying to develop a script that performs the parsing of a log every 1 minute and then generating some statistics. I'm fairly new to programming and this is why I come to ask if I can lend a hand. this is my log: xxxx 16/04/2012 17:00:52 - xxxx714 - E234 - Time= 119 ms.... (8 Replies)
Discussion started by: jockx
8 Replies

5. Linux

Regarding scp with out password

Dear all, I have two servers A and B. I want to do scp with out password between these two servers. I created ssh-keygen and copied the id-rsa.pub file to each of them in authorized_keys. But I could login only from B to A with out password. From A to B it is asking for a password. ... (5 Replies)
Discussion started by: jegaraman
5 Replies

6. UNIX for Advanced & Expert Users

Automated SCP script passing password to preserve source file timestamp

Hi My requirement is i want to copy files from remote server to the local server and also i need to preserve the timestamp of the remote file. By using scp -p , it is working fine in the interactive call but it is not preserving he file timestamp when i use it in the non interactive scp call... (1 Reply)
Discussion started by: skumar75
1 Replies

7. Red Hat

sftp/scp without password

Hi, I want to use sftp/scp without password.How can I do that ?? I plan to use script with scp/sftp and execute by cronjob ,any sample or example?? How can I test the scp/sftp working or not in the same user account , in the same red linux server?? any suggestion ??? (5 Replies)
Discussion started by: chuikingman
5 Replies

8. HP-UX

sftp/scp/ssh script with password as authentication

Hello, Do you guys know set of commands that can incorporate to sftp/scp/ssh to add password in a script to automate file transfer. Our client is not using ssh keys authentication so we are force to create a script to pass the password into the script to transfer files via sftp/scp/ssh. We... (4 Replies)
Discussion started by: james_falco
4 Replies

9. UNIX for Advanced & Expert Users

scp without password

Hi, when I use scp test.jsp user@remote:/tmp/ I'm prompted user@remote's password: How can I avoid it ? Thank you. (8 Replies)
Discussion started by: big123456
8 Replies

10. Shell Programming and Scripting

scp scripting without asking password

I like to copy a file from one server server1 from path path1 to another server server2 to path path2. User logging in both the servers are same say user1 I tried to use ssh to generate public/private key pairs and then copy without prompting for password. These are the steps i followed ... (5 Replies)
Discussion started by: jwala
5 Replies
Login or Register to Ask a Question