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
MAXDB_STMT_PARAM_COUNT(3)						 1						 MAXDB_STMT_PARAM_COUNT(3)

maxdb_stmt_param_count - Returns the number of parameter for the given statement

       Procedural style

SYNOPSIS
int maxdb_stmt_param_count (resource $stmt) DESCRIPTION
Object oriented style int$maxdb_stmt->param_count () maxdb_stmt_param_count(3) returns the number of parameter markers present in the prepared statement. RETURN VALUES
returns an integer representing the number of parameters. EXAMPLES
Example #1 Object oriented style <?php $maxdb = new maxdb("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } if ($stmt = $maxdb->prepare("SELECT name FROM hotel.city WHERE name=? OR state=?")) { $marker = $stmt->param_count; printf("Statement has %d markers. ", $marker); /* close statement */ $stmt->close(); } /* close connection */ $maxdb->close(); ?> Example #2 Procedural style <?php $link = maxdb_connect("localhost", "MONA", "RED", "DEMODB"); /* check connection */ if (maxdb_connect_errno()) { printf("Connect failed: %s ", maxdb_connect_error()); exit(); } if ($stmt = maxdb_prepare($link, "SELECT name FROM hotel.city WHERE name=? OR state=?")) { $marker = maxdb_stmt_param_count($stmt); printf("Statement has %d markers. ", $marker); /* close statement */ maxdb_stmt_close($stmt); } /* close connection */ maxdb_close($link); ?> The above example will output something similar to: Statement has 2 markers. SEE ALSO
maxdb_prepare(3). PHP Documentation Group MAXDB_STMT_PARAM_COUNT(3)
All times are GMT -4. The time now is 12:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy