Want to login as su and perform some command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to login as su and perform some command
# 1  
Old 01-30-2014
Want to login as su and perform some command

Hi All,

I have some set of server and I want to write a code that can go to each server login as su and perform some command and redirect output of the command to the individual file.

The command is working fine in terminal.

1. To login as su: su - username (I have privilege so it won't ask for the password too in command line/terminal).

2. have one command ulimit > serverxyz.txt

I have write the perl script but I am unable to login as su and it just generate


Code:
#!/usr/bin/perl
 
my $file = $ARGV[0];
open SLIST, $file or die $!;
my @allserver = (<SLIST>);
 
foreach my $server (@allserver){
        chomp($server);
 
        `ssh $server su - username -c "ulimit " > $server`;
}

It Generate some message like standard in must be a tty along with below message.

Also I want to turn of this message, so it would be helpful if you can guide how can I avoid this message in output.

Code:
WARNING. You have accessed a private computer system.
Unauthorized access,use,connection,or entry is not permitted
and constitutes a crime punishable by law.......................


Last edited by zaxxon; 01-30-2014 at 03:44 PM.. Reason: Output to code tags too
# 2  
Old 01-30-2014
Try:
Code:
ssh -n $server .....

# 3  
Old 01-30-2014
Code:
#!/usr/bin/perl
 
my $file = $ARGV[0];
open SLIST, $file or die $!;
my @allserver = (<SLIST>);
foreach my $server (@allserver){
        chomp($server);
 
        `ssh -n $server su - username -c "ulimit" > $server\_limit`;
}

still have the same error message......
# 4  
Old 01-30-2014
That message may be /etc/issue or /etc/motd, and there is a chance to suppress it within the configuration file /etc/login.defs.
Look also for hushlogin.
# 5  
Old 01-30-2014
Hi
Thanks but I do not privilege to change any of this file.
# 6  
Old 01-30-2014
You might just have to use grep or sed to remove the unwanted text from the output:

Code:
`ssh $server su - username -c "ulimit " | grep -vE "WARNING|Unauthorized|crime" > $server`;

# 7  
Old 01-31-2014
Early connection errors and /etc/issue message are suppressed with -q
Code:
ssh -qnx $server ...

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Login, excute command, logout Script Help

Good Evening all, After spending the last week or so reading many posts I decided to register and join in. This is my first post on the forum so please forgive me as im new to this, Im after some help in throwing together a quick basic script without using expect to change the password on several... (4 Replies)
Discussion started by: mutley2202
4 Replies

2. Shell Programming and Scripting

Script to monitor for new file with ext .err and size > 0 bytes and perform a action or command

Hi All, I need to create a script to monitor a dir for new files with ext .err and also it should b a non empty files. and perform a action or command . We have a new ETL application that runs on a linux server, every times a etl fails it creates a .err file or updates the existing .err... (4 Replies)
Discussion started by: MAKHAN
4 Replies

3. Shell Programming and Scripting

Help with ssh login and command

Hi I want to make a ssh login and excute a command in the same step. I am trying something like ssh -t -t -Y hostname 'sh myscript' However I recive connection to "host" closed and nothing has happend. I can succesfully log in to the host and then excute my script if I do it in... (2 Replies)
Discussion started by: Mtepe
2 Replies

4. HP-UX

Unable To Perform A "Passwordless" SSH Login To A Server

Greetings! I am trying to perform a passwordless SSH login from a HPUX 11.31 client to a HPUX 11.31 server. Whenever I do a "ssh -l root serverA" from the client, I am prompted for a password. Giving the password, I am able to successfully login. However I am trying to accomplish a... (9 Replies)
Discussion started by: Rob Sandifer
9 Replies

5. HP-UX

pgrep doesn't perform full command line pattern matching

Hi! I need to get PID of some particular process and I wonder if I can use pgrep tool for this purpose. The problem is that pgrep doesn't perform pattern matching on the whole command line, even if I use -f key. Parsing output of ps command is not quite convenient... Also deamon, which PID I need... (2 Replies)
Discussion started by: Sapfeer
2 Replies

6. Solaris

Which logic does ZLOGIN command use to Login ?

Hi All, zlogin command used to login to the zone When we use zlogin is it uses the IP based to login to the zone or it uses Solaris internal logic? Because if it uses IP based suppose if the NIC card is failed due to some reasons then how to Login to the zone.... (4 Replies)
Discussion started by: vijaysachin
4 Replies

7. UNIX for Dummies Questions & Answers

alias command not working after re-login

i create some alias in .cshrc file then i run source .cshrc to refresh it, the alias command work fine but when i relogin again, the alias command is not working... i need to re-run the source .cshrc command so that the alias only workable. any idea on it? (7 Replies)
Discussion started by: lsy
7 Replies

8. UNIX for Dummies Questions & Answers

command to get my login name

Hi Can anyone tell what is the command to get my login name or I am trying to get the users login name, when he uses my shell script? Thx amit (3 Replies)
Discussion started by: amitrajvarma
3 Replies

9. UNIX for Dummies Questions & Answers

Perform a command to multiple files

How do I perform a command to multiple files? For example, I want to look at all files in a directory and print the ones that do not contain a certain string. How do I go about doing this? (4 Replies)
Discussion started by: mcgrawa
4 Replies
Login or Register to Ask a Question