Save the output of the command run as other user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Save the output of the command run as other user
# 15  
Old 02-13-2010
Quote:
Originally Posted by Franklin52
And what to do if you have more then one value > 500? In that case you'll get several lines.
Even if one value is > 500 in last column, i am supposed to perform some specific system diagnostics. But for now in the script, i just want the script to tell me via " echo " that one or more values are > 500. I hope you understand now what i am trying to do and what is the purpose. Thanks
# 16  
Old 02-13-2010
I'm not shure if the format of the given output is different from your original output, do you get the values of the desired column with this command?

Code:
su user -c "YourCommand | awk '{print \$(NF-1)}'"

If you don't get the correct values try to vary the column number e.g. \$(NF-2),\$(NF-3)... and so forth.
Anyway, this should do what you want assuming the column is correct:

Code:
#!/bin/sh

check=`su user -c "YourCommand | awk 'int(\$(NF-1))>500{print \"YES\";exit}' file"`

if [ "$check" == "YES" ]
then
  echo "There are one or more values > 500!!"
else
  echo "Relax..."
fi


Last edited by Franklin52; 02-13-2010 at 12:17 PM.. Reason: Correcting code
# 17  
Old 02-13-2010
Quote:
Originally Posted by Franklin52
I'm not shure if the format of the given output is different from your original output, do you get the values of the desired column with this command?

Code:
su user -c "YourCommand | awk '{print \$(NF-1)}'"

If you don't get the correct values try to vary the column number e.g. \$(NF-2),\$(NF-3)... and so forth.
Anyway, this should do what you want assuming the column is correct:

Code:
#!/bin/sh

check=`su user -c "YourCommand | awk 'int(\$(NF-1))>500{print \"YES\";exit}' file"`

if [ "$check" == "YES" ]
then
  echo "There are one or more values > 500!!"
else
  echo "Relax..."
fi



Smilie Thanks alot buddy. I hope it would work.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run sql query in shell script and output data save as delimited text

I want to run sql query in shell script and output data save as delimited text (delimited text would be comma) Code: SPOOL_FILE=/pgedw/dan.txt SQL=/pgedw/dan.sql sqlplus -s username/password@myhost:port/servicename <<EOF set head on set COLSEP , set linesize 32767 SET TRIMSPOOL ON SET... (8 Replies)
Discussion started by: Jaganjag
8 Replies

2. Shell Programming and Scripting

How to execute command remotely as sudo and save the output locally?

Hello , I am trying to run a NetBackup command in remote server. Also this command can only be run by root so I am using sudo . Also I want the output of the command locally in a file. The below command asked for password , ran successfully and showed Output on my local server screen ... (2 Replies)
Discussion started by: rahul2662
2 Replies

3. Shell Programming and Scripting

Save value from output of Corestat and save in a list for each core

I am trying to modify the "corestat v1.1" code which is in Perl.The typical output of this code is below: Core Utilization CoreId %Usr %Sys %Total ------ ----- ----- ------ 5 4.91 0.01 4.92 6 0.06 ... (0 Replies)
Discussion started by: Zam_1234
0 Replies

4. Shell Programming and Scripting

Reading ls -l output line by line awk the user name and su user to run commands

Using ksh on AIX what I am trying to do is to read the ls -l output from a file in a do while loop line by line. Extract the user name(3rd field) and the directory/file name(9th field) using awk and save them into variables. su -c to the user and change directory/file permisions to 777. Script I... (13 Replies)
Discussion started by: zubairom
13 Replies

5. Shell Programming and Scripting

how to save an output of a command in a variable

Hi, in shell script, i have the command swstart -p which returns an output. i want to store the output of this command into a variable. how i can do that excerpt from the script #!/usr/bin/ksh # # # # Program: swstart -p # # Description: Starts the sentinels on Slave server ... (4 Replies)
Discussion started by: lookinginfo
4 Replies

6. Shell Programming and Scripting

Save cURL verbose output to file or do it like browser "save as.."

hi there ! i have exactly the same problem like this guy here https://www.unix.com/shell-programming-scripting/127668-getting-curl-output-verbose-file.html i am not able to save the curl verbose output.. the sollution in this thread (redirecting stderr to a file) does not work for me.... (0 Replies)
Discussion started by: crabmeat
0 Replies

7. UNIX for Dummies Questions & Answers

how to save the output of command in tcl/expect

hi, everyone: I just wonder how to save the output of command, I mean everything, save as a string into a variable. another question is I try to ls the details of a directory, but it works in the shell, not in the script. for example code: ls -ltr *se100* | grep ^- | tail -1 | awk '... (1 Reply)
Discussion started by: allenxiao7
1 Replies

8. Shell Programming and Scripting

to save output of a command in hash variable

Hi all, is it possible to save the output of a unix command executed in perl to be saved in hash variable.. like i have the command `find $mypath ! -user mainuser -printf \"\%u \%h\\n\"`; this will print all the users other than mainuser with their paths. so is possible to capture... (2 Replies)
Discussion started by: saapa
2 Replies

9. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

10. Shell Programming and Scripting

How to run a command with some other user id

Hi Say I am running a script using my user id csaha. How can I run any specific command in the same sctipr using any other user id (say root). Definitely I have the password of root. Any idea how the same can be achieved ??? Example: I need to run a script using my id (csaha) only on... (4 Replies)
Discussion started by: csaha
4 Replies
Login or Register to Ask a Question