Help with login script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with login script.
# 1  
Old 03-19-2013
Help with login script.

Guys I need to write a script that will login to over 480 servers and run the last -n 45 "userid" | tail -1. OK, I am terrible at writting scripts. So I need the script to run this command and forward the output to my main server in /var/tmp/output. PLEASE HELP. Smilie
# 2  
Old 03-19-2013
Secure Shell (SSH) would be an option. If you have ssh-keys setup, then you can use SSH to run remote commands.

Syntax:
Code:
ssh [user@]hostname [command]

# 3  
Old 03-19-2013
Ok, so your saying something like this should work for 480 boxes?

ssh [user@]hostname last -n 45 "userid" | tail -1?
Will this work if I put in a shell script like the above?
# 4  
Old 03-19-2013
Yes, should work in script, but you'll need to set up passwordless authentication on your hosts or it will demand a password for every login.

Also, put quotes around the pipe so it gets executed on the remote side instead of the local.

Code:
ssh user@host last -n 45 "userid" "|" tail -n 1

# 5  
Old 03-19-2013
Yes, if you have all the user name and host name listed in a file, then use a while loop and run remote command
Code:
while read user hostname
do
   ssh -n "${user}@${hostname}" last -n 45 "userid" "|" tail -n 1
done < listfile

Use -n option to make it work in a loop.
This User Gave Thanks to Yoda For This Post:
# 6  
Old 03-19-2013
SWEET!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

---------- Post updated at 12:37 PM ---------- Previous update was at 12:30 PM ----------

I said that before I thought about it. I only have one user that has a ssh key setup. I want this user to ssh to all boxes and run the command.
# 7  
Old 03-19-2013
So simply login as this user who has ssh-keys setup done.

Write & run the script from this user account.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script as login shell (passing args to login shell)

Hello all, for security reasons my compagny imposes that my script be launch remotly via ssh under the users login shell. So serverA launches the ssh command to serverB which has a local user with my script as a login shell. Local script works like a charm on his own. serverB$ grep... (20 Replies)
Discussion started by: maverick72
20 Replies

2. OS X (Apple)

Login/Logout script

Dear readers I use SnowLeopard 10.6.2 and need to do some special tasks at login and logout of an sepcific user. My problem is, how do I send a string "login" respectively "logout" from computer "A", where the login/logout script runs, to computer "B" where some other tasks need to be done. ... (3 Replies)
Discussion started by: tthaler
3 Replies

3. Programming

Login script for unix ?

Anyone know of a script or program in a unix platform that will allow one login and password for three databases ? Say i have a social site that has a video site and phpBB3 forum but i want them connected as one login. I heard there is a script that does that , anyone know the name or where to get... (0 Replies)
Discussion started by: rumrunner439
0 Replies

4. Shell Programming and Scripting

Login Script

Can anybody help in writing a script that takes username and password and then successfully login onto windows operating system box? For example 1. I have a box A with Linux OS. 2. I have another box B with windows OS. How to login onto boxB from boxA? (3 Replies)
Discussion started by: vinna
3 Replies

5. Shell Programming and Scripting

Help on a login script

I am trying to get a script together so when any user logs into the system it will display a message. After the user answers the question based on the answer they will proceed into the system or be logged out. I only want the person to get prompted once per message. Below is what I have in all... (1 Reply)
Discussion started by: gbarnes
1 Replies

6. Shell Programming and Scripting

How can we ssh login with script?

Hi all, Normally, we give ip address to login with ssh like ssh 172.168.0.1 And we can give login name to ssh like ssh -l root 172.10.0.21 Then the shell asks the password, we enter the password and login to the system. While using the script file, we are not able to supply the password to... (5 Replies)
Discussion started by: pcsaji
5 Replies

7. Shell Programming and Scripting

Automatic login script

Hi, I'm a beginner in unix.As a part of my script i need to remote logon using ssh. my script run as being asked for password and logons only after the user enters the password correctly. But my script stops executing after that as I login to a different server(different shell if i'm right).... (3 Replies)
Discussion started by: dayanand
3 Replies

8. UNIX for Dummies Questions & Answers

Login script

Hi, I wrote a script for backing up a application database. When I run the script from command line, it works great.. But when I add that script to login profile of some user , it does not work ... ******************************************* backup script:- (databasebk) #!/bin/ksh # set... (3 Replies)
Discussion started by: newtoxinu
3 Replies

9. Shell Programming and Scripting

Script with SU Login

I'm attempting to write a script where it temporarily would login as Super User to change some file permissions, cats the files, then exits. Can this be done by script with no manual(human) input? thanks (3 Replies)
Discussion started by: bkhviking
3 Replies

10. UNIX for Dummies Questions & Answers

Login and logout script

Hi all I know ho I can run a script when a user logs in, viz using the .login or .profile file, however what can I use to run a script when a user logouts ? Thanks J :confused: (1 Reply)
Discussion started by: jhansrod
1 Replies
Login or Register to Ask a Question