Sponsored Content
Top Forums Shell Programming and Scripting [How To?] Run shell script and get output into another shell. Post 302334528 by Thireus on Thursday 16th of July 2009 03:57:42 AM
Old 07-16-2009
[How To?] Run shell script and get output into another shell.

Hi guys,

I have a simple question, I want to store the output of the following command:

Quote:
sudo iotop -t 0 -C 3 | grep "load: "
As you can see it is running all the time, and we get a new line every 3sec.

I just want to store these new lines into a single variable, so I can use it into a script.

To clear the screen, and do not print lines after the others when iotop is running just delete "- C".

I DO NOT WANT TO STORE THE OUTPUT ON THE DRIVE!!!
I DO NOT WANT TO KILL IOTOP, IT MUST BE RUNNING ALL THE TIME IN BACKGROUND!!!

The idea is to do not write on the drive! Just store the output into a single variable called $Activity.

For example:

Code:
Activity=$(sudo iotop -t 0 3 | grep "load: ") &

While $Activity... do blahblah... done

But the fact is that nothing can be stored into Activity Smilie
So I have tried to know if something can be done to read the last output of a specified PID. But I need help on that point too :-/ I don't know how to do it.

Please help... Smilie

---------- Post updated at 09:57 AM ---------- Previous update was at 02:02 AM ----------

Ok, here is my code:

Code:
sudo iotop -t 0 -C 3 | grep "load: " | script.sh

script.sh:

Code:
#!/bin/sh

  while read data
  do
      echo "[$(date +"%D %T")] $data" >> log_activity.txt
  done

But nothing is read Smilie
 

9 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

How to Run a shell script from Perl script in Parent shell?

Hi Perl/UNIX experts, I have a problem in running a shell script from my perl script (auto.pl). I run the perl script using perl auto.pl from the shell prompt The shell script picks the files in "input" folder and procesess it. The shell script blue.sh has this code. export... (16 Replies)
Discussion started by: hifake
16 Replies

3. Shell Programming and Scripting

Help need to make a shell script run for ffmpeg vhook watermaking in shell

i have a small problem getting a batxh shell script to run in shell this is the code the problem seems to be centered around the ffmpeg command, something maybe to do with the ' ' wrapping around the vhook part command this is a strange problem , if i take the ffmpeg command and... (1 Reply)
Discussion started by: wingchun22
1 Replies

4. Shell Programming and Scripting

How to run cmds after changing to a new env (shell) in a shell script

Hi, I am using HP-UNIX. I have a requirement as below I have to change env twice like: cadenv <env> cadenv <env> ccm start -d /dbpath ccm tar -xvf *.tar ccm rcv .... mv *.tar BACKUP but after I do the first cadenv <env> , I am unable to execute any of the later commands . ... (6 Replies)
Discussion started by: charlei
6 Replies

5. Fedora

Re: How To Run Shell Script

Hi , I Have Installed Red Hat Linux 5(Guest O.S) In Vmware And Host O.S Is Windows 7 .I Am Unable To Run Script File In It Is Giving Error E32: No File Name.For All Basic Commands It's Working Fine Like Cat ,Cmp.,etc . I Logging As Root User And Working Under The Directory I Am Using... (3 Replies)
Discussion started by: anudeepkumar123
3 Replies

6. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

7. 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

8. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

9. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies
IOTOP(8)						      System Manager's Manual							  IOTOP(8)

NAME
iotop - simple top-like I/O monitor SYNOPSIS
iotop [OPTIONS] DESCRIPTION
iotop watches I/O usage information output by the Linux kernel (requires 2.6.20 or later) and displays a table of current I/O usage by pro- cesses or threads on the system. At least the CONFIG_TASK_DELAY_ACCT, CONFIG_TASK_IO_ACCOUNTING, CONFIG_TASKSTATS and CONFIG_VM_EVENT_COUN- TERS options need to be enabled in your Linux kernel build configuration. iotop displays columns for the I/O bandwidth read and written by each process/thread during the sampling period. It also displays the per- centage of time the thread/process spent while swapping in and while waiting on I/O. For each process, its I/O priority (class/level) is shown. In addition, the total I/O bandwidth read and written during the sampling period is displayed at the top of the interface. Use the left and right arrows to change the sorting, r to reverse the sorting order, o to toggle the --only option, p to toggle the --pro- cesses option, a to toggle the --accumulated option, q to quit or i to change the priority of a thread or a process' thread(s). Any other key will force a refresh. OPTIONS
--version Show the version number and exit -h, --help Show usage information and exit -o, --only Only show processes or threads actually doing I/O, instead of showing all processes or threads. This can be dynamically toggled by pressing o. -b, --batch Turn on non-interactive mode. Useful for logging I/O usage over time. -n NUM, --iter=NUM Set the number of iterations before quitting (never quit by default). This is most useful in non-interactive mode. -d SEC, --delay=SEC Set the delay between iterations in seconds (1 second by default). Accepts non-integer values such as 1.1 seconds. -p PID, --pid=PID A list of processes/threads to monitor (all by default). -u USER, --user=USER A list of users to monitor (all by default) -P, --processes Only show processes. Normally iotop shows all threads. -a, --accumulated Show accumulated I/O instead of bandwidth. In this mode, iotop shows the amount of I/O processes have done since iotop started. -k, --kilobytes Use kilobytes instead of a human friendly unit. This mode is useful when scripting the batch mode of iotop. Instead of choosing the most appropriate unit iotop will display all sizes in kilobytes. -t, --time Add a timestamp on each line (implies --batch). Each line will be prefixed by the current time. -q, --quiet suppress some lines of header (implies --batch). This option can be specified up to three times to remove header lines. -q column names are only printed on the first iteration, -qq column names are never printed, -qqq the I/O summary is never printed. SEE ALSO
ionice(1), top(1), vmstat(1), atop(1), htop(1) AUTHOR
iotop was written by Guillaume Chazarain. This manual page was started by Paul Wise for the Debian project and is placed in the public domain. April 2009 IOTOP(8)
All times are GMT -4. The time now is 11:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy