Sponsored Content
Top Forums Shell Programming and Scripting Use script to monitor command output question? (like Linux watch) Post 302559524 by nnnnnnine on Tuesday 27th of September 2011 09:53:32 AM
Old 09-27-2011
Use script to monitor command output question? (like Linux watch)

Hi

I want to write a script, help me to monitor command output.

This script like Linux "watch" command.

Below is my script:
Code:
[root@host scripts]# cat watch.sh 
#!/bin/bash

while true
do
        clear
        echo "command: $*"
        ( $* )
        sleep 2
done

Then I run this script below
Code:
[root@station54 scripts]# ./watch.sh ls -l

Output like below
Code:
Interval 2 sec, Command: ls -l
total 40
drwxr-xr-x 2 root root 4096 Sep 27 21:34 aaa
-rw-r--r-- 1 root root    0 Sep 27 21:34 bbb
-rw-r--r-- 1 root root    0 Sep 27 21:34 ccc
-rw-r--r-- 1 root root    0 Sep 27 21:34 ddd
-rw-r--r-- 1 root root    0 Sep 27 21:34 eee
-rw-r--r-- 1 root root    0 Sep 27 21:34 fff
-rw-r--r-- 1 root root    0 Sep 27 21:34 ggg
-rwxr--r-- 1 root root   93 Sep 27 21:36 watch.sh

Then I run this script again "with pipe line and grep." , and every thing wrong...(screen not clear ...etc)
Code:
[root@station54 scripts]# ./watch.sh ls -l | grep eee

BUT Output like below
Code:
[root@station54 scripts]# ./watch.sh ls -l | grep eee
-rw-r--r-- 1 root root    0 Sep 27 21:34 eee
-rw-r--r-- 1 root root    0 Sep 27 21:34 eee  
-rw-r--r-- 1 root root    0 Sep 27 21:34 eee 
.
.

I except output like below
Code:
Interval 2 sec, Command: ls -l | grep eee
-rw-r--r-- 1 root root    0 Sep 27 21:34 ddd

How to complete this ....? please give me a hand.

Thanks,
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Linux watch command on AIX?

On Linux I could use the `watch` command to loop a command X times. Is there a similar command on AIX? If not, is there a way to write a loop on the command line to do this? Linux: watch -d -n 60 'db2 list applications show detail | grep Connect | wc -l' AIX: ??? (2 Replies)
Discussion started by: djschmitt
2 Replies

2. Solaris

Any command to watch output repeatedly??

Hi Experts,, Can you tell me "Is there any command in solaris that gives the output repeatedly for every x seconds" when used with other commands like ls,du,df,etc..Like prstat updates its output for every 5 seconds.. If i want to view how much of disk usage is going on a filesystem for every... (2 Replies)
Discussion started by: sdspawankumar
2 Replies

3. Shell Programming and Scripting

script to monitor mount points on linux box

Hi, the following shell script is not working on linux box sugeestions appreciated. FILE1=/tmp/check1.txt FILE2=/tmp/check2.txt df -k | awk '{if (NR != 1) print $5 $6}' > ${FILE1} awk -F"%" '{if ($1 > 90) print "Warning: Filesystem " $2 " over 90% threshold (" $1 "%)"}' ${FILE1} >... (7 Replies)
Discussion started by: prakash.gr
7 Replies

4. Shell Programming and Scripting

Need help on Linux script to monitor hard drive space

I'm new to Linux and have very limited experience with shell scripts in general. I am taking a class and I have to research online and come up with a shell script that monitors disk space. I also have to be able to explain it line by line. I've researched various sites and came across this shell... (3 Replies)
Discussion started by: wgreg23
3 Replies

5. Shell Programming and Scripting

Command Output Question

Hi everyone-- I'm new to these forums and shell scripting, and I'm trying to write a script that checks if a particular ip is pingable My idea was to check if the output of the command ping <some ip> -c 1 -w 1 had the string: "1 packet transmitted, 1 received"How would I go about doing this?... (2 Replies)
Discussion started by: Prodiga1
2 Replies

6. Shell Programming and Scripting

How to monitor a command inside shell script

Hi All, Is there any way to monitor a command inside shell script ? I have a script inside which I have a tar command which zips around 200GB data. tar zcvf $Bckp_Dir/$Box-BaseBackup-$Day.tar.gz * --exclude 'dbserver_logs/*' --exclude postmaster.pid --exclude 'pg_xlog/*' I want to... (3 Replies)
Discussion started by: sussus2326
3 Replies

7. Shell Programming and Scripting

Storing the Linux command output to an array in perl script

Hi I am trying to store the output of a command into an array in perl script. I am able to store but the problem is i am unable to print the array line with one line space. i mean i inserted the \n in loop ...but not getting the result. I have written like this #!/usr/bin/perl @a =... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

8. Shell Programming and Scripting

Using the watch command

so i have a very long script which i have to run. when i run this script, i want to monitor the the openssl commands it runs. the way ive attempted to do this is: watch -t -n 1 "(date '+TIME:%H:%M:%S' ; ps aux | egrep openssl | egrep -v grep)" 2>&1 | tee -a logfile the above command is... (2 Replies)
Discussion started by: SkySmart
2 Replies

9. Post Here to Contact Site Administrators and Moderators

Need script to monitor open file in Linux

Kindly advice with shell script to monitor open file in linux, if the open file count is greater then 5000 then send me an email.. command : lsof | wc -l (0 Replies)
Discussion started by: adminhelp
0 Replies

10. Programming

Script to monitor progress of find/exec command

hi all, i want to monitor the progress of a find and exec command, this is the code i use - find . -type f -exec md5sum {} \; >> /md5sums/file.txt this command works and produces a text file with all the md5sums but while running it doesnt show the progress is there anyway i can do this... (4 Replies)
Discussion started by: robertkwild
4 Replies
dsenableroot(8) 					    BSD System Manager's Manual 					   dsenableroot(8)

NAME
dsenableroot -- enables or disables the root account. SYNOPSIS
dsenableroot [-d] [-u username] [-p password] [-r rootPassword] DESCRIPTION
dsenableroot sets the password for the root account if enabling the root user account. Otherwise, if disable [-d] is chosen, the root account passwords are removed and the root user is disabled. A list of flags and their descriptions: -u username Username of a user that has administrative privileges on this computer. -p password Password to use in conjunction with the specified username. If this is not specified, you will be prompted for entry. -r rootPassword Password to be used for the root account. If this is not specified for enabling, you will be prompted for entry. EXAMPLES
-dsenableroot Your username will be used and you will be queried for both your password and the new root password to be set to enable the root account. -dsenableroot -d Your username will be used and you will be queried for only your password to disable the root account. -dsenableroot -u username -p userpassword -r rootpassword The supplied arguments will be used to enable the root account. -dsenableroot -d -u username -p userpassword The supplied arguments will be used to disable the root account. Mac OS August 08 2003 Mac OS
All times are GMT -4. The time now is 01:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy