Sponsored Content
Top Forums Shell Programming and Scripting How to monitor a command inside shell script Post 302490836 by agama on Tuesday 25th of January 2011 08:22:02 PM
Old 01-25-2011
This should get you started. I avoid bash, and have marked the one statement that I know you'll need to change if you wish to use bash over Ksh.

Code:
#!/usr/bin/env ksh

# function that does work to be monitored.  when it is finished
# it deletes the marker file passed as $1
function runme
{
    # tar command would go here
    # some dummy work for easy testing instead of tar command
    typeset i=0
    while (( $i < 50 ))
    do
        ps -elf >> /tmp/out
        i=$(( $i + 1 ))
        sleep 1
    done
    # end of dummy work

    rm $1       # remove marker to indicate done
}

# function to monitor and report every few seconds to the tty
function watch
{
    printf "started watching: %s\n" "$(date)"
    while [[ -f $1 ]]     # keep watching until runme removes the marker ($1)
    do
        # replace /tmp/out with your filename, or pass filename in (better)
        ls -hl /tmp/out | read junk junk junk junk size junk    # WARNING: not bash friendly
        printf "%s: cur size: %-10s\r" "$(date)" "$size"
        sleep 2
    done

    printf "\n"
}

marker=/tmp/marker          # watch function loops until this is gone
>$marker                    # create it
runme $marker &             # start function to do work
watch $marker               # update progress until done

Have fun!
This User Gave Thanks to agama For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies

2. Shell Programming and Scripting

Using cp command inside shell scrip

Hi, First i would like to say that im a unix begginer. I have a file named /tmp/sample.lst that contain about 20 rows like the following two : '/tmp/aa.txt' '/temp/aa.txt' '/tmp/xx.txt' '/temp/xx.txt' Inside a ksh script i would like to do the following task: add the cp command at... (2 Replies)
Discussion started by: yoavbe
2 Replies

3. UNIX for Dummies Questions & Answers

how to get the output of a grep command to a file inside a shell script

hi, i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (1 Reply)
Discussion started by: kripssmart
1 Replies

4. Shell Programming and Scripting

how to redirect the output of a grep command to a file inside a shell script

hi, i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (11 Replies)
Discussion started by: kripssmart
11 Replies

5. Shell Programming and Scripting

C Shell - Command Inside a Loop

I have a command nested in some while loops to parse some data that looks something like this. while ($condition) while ($condition) ... gzcat /dir/$fileName.gz | grep $searchString > out_file end end On the first loop, the command is executed properly (and takes maybe 10... (3 Replies)
Discussion started by: hobbers
3 Replies

6. Shell Programming and Scripting

Error while using sqlplus command inside 'if' condition in an unix shell script

Hi all, I am using the below given sqlplus command in my unix script to invoke a stored procedure which returns a value .It works fine. RET_CODE=$(/opt/oracle/product/10.2.0.4.CL/bin/sqlplus -S $USER/$PASSWD@$DB_NAME <<EOF EXEC MY_PKG.MY_SP (:COUNT); PRINT COUNT; commit; ... (6 Replies)
Discussion started by: Shri123
6 Replies

7. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

8. Shell Programming and Scripting

Not correct processing of “\ “ in names of dirs inside shell script (tar command - system backup scr

Hello, Recently, I've started with shell scripting, and decided to write a script for my system backup using tar. When I was dealing with tar execution inside shell script I found this, inside shell we have the following code: tar $TAR_PARAMS $ARCHIVE_FILE $EXCLUDE $BACKUP_STARTwith... (6 Replies)
Discussion started by: ilnar
6 Replies

9. Shell Programming and Scripting

Can i use if else inside expect command in shell script?

hii,, I am trying to automate jira. during my scripting using bash script, in the terminal i got the terminal message like this: "Configure which ports JIRA will use. JIRA requires two TCP ports that are not being used by any other applications on this machine. The HTTP port is where you... (1 Reply)
Discussion started by: nithinfluent
1 Replies

10. Shell Programming and Scripting

Sql command inside shell script runs without giving anything back as outout

#!/bin/sh # This script returns the number of rows updated from a function echo "The execution is starting ....." sqlplus -silent $UP <<EOF set serveroutput on set echo off set pagesize 0 VAR no_rows_updated NUMBER; EXEC :no_rows_updated :=0; DECLARE CURSOR c_update is SELECT * FROM... (4 Replies)
Discussion started by: LoneRanger
4 Replies
REPLMARKS(1)						      General Commands Manual						      REPLMARKS(1)

NAME
replmarks - replace triangular markers in a RADIANCE scene description SYNOPSIS
replmarks [ -e ][ -m newmod ][ -s scale ] { -x objfile | -i octree | -I mesh } modname .. [ file .. ] DESCRIPTION
Replmarks replaces triangular markers identified by the modifier modname in each scene description file and writes the result to the stan- dard output. The -x option indicates that each marker should be replaced by an appropriate xform(1) command on objfile. The -i option indicates that each marker should be replaced by an instance of octree. The -I option indicates that each marker should be replaced by an instance of the Radiance mesh mesh. One of these three options must appear on the command line, along with modname, the modifier used by markers in the file. Multiple modifiers may be given, as long as each one is preceded by its own -x or -i option. The transformation for each marker is determined by its location and orientation. A marker should be a right triangle pointing like a half-arrow in the direction of the transformed x-axis, x'. The longest side is the hypoteneuse, the second longest side is the x'-axis, and the third longest side indicates the direction of the y'-axis. Any additional sides will be ignored (ie. a quadrilateral may be used instead of a triangle if the extra side is small). The z'-axis is determined by the cross product of the x' and y' axes, and the origin is the common vertex between x' and y'. The size of the marker is ignored unless the -s option is used, where scale is a multiplier for the x'-axis length to indicate the total scale factor. For example, a scale value of 5 with a marker length of .5 would result in a total scale factor of 2.5 to be used in the transformation. The -e option causes commands in the file to be expanded, and is required to replace markers from commands in the input file. Even with this option, replmarks will not examine objects for markers. Specifically, an object included by replmarks as a result of a -x expansion will be transferred verbatim, without regard to any surfaces therein that might have been considered as marks if they were on the main input. The -m option causes all replaced objects to be given the modifier newmod. Otherwise, the new object surfaces will use their originally defined modifiers. A different replacement modifier may be given for each marker type. The marker modifier name itself is only used to identify markers, and will not appear in the output in any form. If no input file is given, the standard input is read. EXAMPLE
To replace all polygons with the modifier ``knobs'' in the file input with a transformed ``knob.rad'' and write the result to output: replmarks -x knob.rad knobs input > output To use instances of ``tree.oct'' with scaling set to three times the tree marker length: replmarks -s 3 -i tree.oct tree input > output AUTHOR
Greg Ward SEE ALSO
arch2rad(1), ies2rad(1), xform(1) RADIANCE
3/24/94 REPLMARKS(1)
All times are GMT -4. The time now is 03:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy