Sponsored Content
Top Forums Shell Programming and Scripting Not able to store command inside a shell variable, and run the variable Post 302473161 by gvinayagam on Friday 19th of November 2010 05:16:36 AM
Old 11-19-2010
Thanks, So do you mean that pipline command should not be stored and reused ?

My code is like following

Code:
function checkProcessIdeHosts()
{
 unique_host=$1
 
 no_unique_hosts_prc=`sed -e ' /#/d' $configFile | awk -v appcode="$appcode" -F"$config_del" '{ if ($1 == appcode ) print $0 }' | awk -v unique_host="$unique_host" -F"$config_del" '{ if ( $2 == unique_host ) print $0 }'|wc -l`
 if [ $no_unique_hosts_prc -eq 1 ]
 then 
  checkProcessModule `sed -e ' /#/d' $configFile | awk -v appcode="$appcode" -F"$config_del" '{ if ($1 == appcode ) print $0 }'| awk -v unique_host="$unique_host" -F"$config_del" '{ if ( $2 == unique_host ) print $0 }'`
 else
  for proc_det in `sed -e ' /#/d' $configFile | awk -v appcode="$appcode" -F"$config_del" '{ if ($1 == appcode ) print $0 }'| awk -v unique_host="$unique_host" -F"$config_del" '{ if ( $2 == unique_host ) print $0 }'`
  do
          checkProcessModule $proc_det 
   sleep 5
  done
 fi
}

I am using the command "sed -e ' /#/d' $configFile | awk -v appcode="$appcode" -F"$config_del" '{ if ($1 == appcode ) print $0 }' | awk -v unique_host="$unique_host" -F"$config_del" '{ if ( $2 == unique_host ) print $0 }'" in multiple places, in case of updates to the command then I have to make the same changes in multiple places, i want to get rid of that, i can not use functions for this kind of substitutions

Last edited by pludi; 11-19-2010 at 06:37 AM.. Reason: code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep results to store in a shell variable

I have the results of a grep with -n store in a shell variable ie VAR=`grep -n -e 'PATTERN' file` How ever I am missing the line breaks in the variable , How do I store the resualts of grep with many lines in to a variables. I want the varable should be the sawmway as we do the grep grep... (3 Replies)
Discussion started by: jojan
3 Replies

2. UNIX for Dummies Questions & Answers

How to Store command O/P to a variable...

Hi all.. I got a problem.. Its easy to redirect o/p to a file.. But Is it possible to redirect the O/P to a variable? For example: I've a command in my script: string1=cut -d ':' -f2 file.txt When I do: echo $string1 The value is empty... Pls suggest me how to store the value... (7 Replies)
Discussion started by: smartbuddy
7 Replies

3. Shell Programming and Scripting

how to store grep command in a Variable

I have a variable A echo $A 5060 I am exporting the value X,Y,Z and it id fetching right thing and When I run C=`${X} -l ${Y} ${Z} "trap '' INT;. ~/.profile >/dev/null 2>/dev/null; netstat -na | grep \$A`" here it is going to same directory and also running netstat -na | grep 5060 ... (4 Replies)
Discussion started by: madhusmita
4 Replies

4. Shell Programming and Scripting

Store highest filename from ls command to a variable

I am sure it has been answered in some form or the other in this forum but trust me I have spent last couple of hours looking for an answer but can't find it. I want to do a very simple operation within my script. Let's say I have 4 files with the names file1.log, file2.log, file3.log and... (6 Replies)
Discussion started by: sssccc
6 Replies

5. Shell Programming and Scripting

Using variable to store of find command

Hello Experts I am newbie to unix and writing one script to make archive files Problme i am facing is : I have used find command to find the type of files and I am storing find command results in a variable. When I echo the variable I can see that path is printed properly but when i am... (5 Replies)
Discussion started by: mitsyjohn
5 Replies

6. Shell Programming and Scripting

To store the file name o/p from find command in to a variable

Hi How to use a variable to store the filename of a file which was found by the 'find' command. can this be practical-->var = find . -name "filename.dat" Please help.. (1 Reply)
Discussion started by: ayyappaas
1 Replies

7. Shell Programming and Scripting

store last command exit status in variable in shell script

Hello All My req is to store the exit status of a command in shell variable I want to check whether the file has header or not The header will contain the string DATA_ACQ_CYC_CNTL_ID So I am running the command head -1 $i | grep DATA_ACQ_CYC_CNTL_ID Now I have to check if... (6 Replies)
Discussion started by: Pratik4891
6 Replies

8. Shell Programming and Scripting

How to store the return value of a command into a variable?

I want to store the return value of grep -c string filename into a variable, say count. How do I do that? For example if grep -c "string" "filename" shows 0 on executing it in the sh shell then I want to store this 0 in a variable. Is it possible? :D (5 Replies)
Discussion started by: navienavnav
5 Replies

9. Shell Programming and Scripting

Store command inside variable

Is it possible to store a command inside a variable? i want this piece to be stored inside a variable, so i can use it later in a different command $u | cut -d " " -f 2 var="$u | cut -d " " -f 2" eval $var I tried to use eval but I receive this error: -f 2: command not found ... (5 Replies)
Discussion started by: velos
5 Replies

10. Programming

Python - store output of command to a variable

I am trying to store output of python command in variable. Could you please help how I can do that ? For example I am executing the following command - "CentOS" in server_desc The output would be True or False I would like to store the output in a variable say outPut and use condition... (4 Replies)
Discussion started by: atanubanerji
4 Replies
runacct(8)						      System Manager's Manual							runacct(8)

NAME
runacct - Runs daily accounting SYNOPSIS
/usr/sbin/acct/runacct [mmdd] [State ...] DESCRIPTION
The runacct command is the daily accounting shell procedure. This shell procedure is normally invoked from the cron daemon to process con- nection, fee, disk usage, queuing (printer), and process accounting database files for the current day. The runacct shell procedure pro- duces a /var/adm/acct/nite/dayacct binary daily accounting file and also produces summary files, which the prdaily shell procedure uses to generate ASCII daily file /var/adm/acct/sum/rprtmmdd or to generate files used for billing for the use of various system resources. The /var/adm/acct/nite/dayacct binary daily accounting file is used by the acctmerg command. The acctmerg command adds records from the dayacct file to the /var/adm/acct/sumtacct file. The /var/adm/acct/sumtacct file is a cumulative summary of system resources used during the accounting period. The sumtacct file is used by the monacct command to produce the monthly accounting summary file, /var/adm/acct/fiscal. The runacct command has two parameters that you may enter from the keyboard whenever you must restart the runacct shell procedure. The date parameter, mmdd, is used to specify the day and month for which you want to rerun the accounting shell procedure. The State parameter is used to restart the runacct shell procedure from any of its 13 states. Recovery from a run failure and the runacct shell procedure restart is described under the Restarting Runacct heading on the next page. The runacct command protects active accounting and summary files whenever a run-time error occurs. During execution, the state-to-state progress of the runacct shell process is recorded by writing descriptive messages to the /var/adm/acct/nite/active file. Whenever the runacct shell process detects a run-time error, a mail message is sent to the superuser (root) and to the user named adm when environment variable MAILCOM is set to mail root adm. After writing the mail message the runacct shell procedure aborts. The runacct shell procedure also creates the temporary file named lock in subdirectory /var/adm/acct/nite. This file is used to prevent simultaneous calls to the runacct shell procedure. The runacct shell procedure also uses the lastdate file, in the same subdirectory, to prevent more than one invocation of the runacct command per day. The runacct States The runacct shell procedure is processed in 13 separate restartable states. When the runacct process completes each state, the name of the next state to undergo execution is written to the /var/adm/acct/nite/statefile file. The runacct procedure processes the various states named in the leftmost column below, in the order given. Moves the active accounting files to working files and restarts the active files. Verifies the integrity of the /var/adm/wtmp file and corrects date changes when necessary. Calls the acctcon1 command to write connect session records. Converts connect session records from the /var/adm/wtmp file to total accounting records in total format defined by tacct structure members in the private tacct.h header file. Converts process accounting records from the /var/adm/pacct* file(s) into total accounting records (see CONNECT2 above). Merges the connect and process total accounting records. Converts the output obtained with the chargefee command into total accounting records (see CONNECT2 above) and merges them with other total accounting records. Merges disk accounting records with connect, process, and fee total accounting records. Sorts queue (printer) accounting records, converts them into total accounting records (see CONNECT2 above), and merges them with other total accounting records. Merges the daily total accounting records in the /var/adm/acct/nite/dayacct file with summary total accounting records in the /var/adm/acct/sum/tacct file. Produces command summaries in the file /var/adm/acct/sum/cms. When the shell procedure /var/adm/siteacct exists, and the runacct shell procedure enters this state, the /var/adm/siteacct is called to perform site-dependent account record processing. Deletes all temporary files and exits. Restarting runacct To restart the runacct shell process after it fails, do the following: Check the /var/adm/acct/nite/active file for diagnostic messages. Repair records in any damaged database files, such as /var/adm/pacct or /var/adm/wtmp. Remove the /var/adm/acct/nite/lock and /var/adm/acct/nite/lastdate files. Before restarting the runacct shell procedure, you must specify the mmdd parameter of the runacct com- mand. This parameter specifies the month and day for which the runacct command is to rerun the accounting shell process. The runacct shell procedure determines the entry point for processing by reading the /var/adm/acct/nite/statefile file. To override this default action, specify a state listed above on the runacct command line. It is not a good idea to restart the runacct command in the SETUP state. Instead, perform set-up actions manually and restart accounting in the WTMPFIX state by entering the following command: runacct mmdd WTMPFIX Should the runacct process fail during its PROCESS state, remove the last /var/adm/acct/nite/ptacct*.mmdd file before restarting the runacct shell process because the file does not complete until the next state is entered. EXAMPLES
To start daily accounting procedures for the use of various system resources, add the following command line to a crontabs file so that the runacct shell procedure is automatically called by the cron daemon. 0 4 * * 1-6 /usr/sbin/acct/runacct 2 > /var/adm/acct/nite/accterr This example shows the instructions that the cron daemon reads and then executes. The runacct shell procedure runs at 4:00 a.m. (0 4) every Monday through Saturday (1-6) and redirects errors from the standard error output (2 >) to the /var/adm/acct/nite/accterr file. This com- mand typifies accounting instructions normally passed to the cron daemon from the runacct shell procedure. (See the System Administration.) To start daily accounting procedures for system resources from the command line (start the runacct command), enter: nohup /usr/sbin/acct/runacct 2> /var/adm/acct/nite/accterr& Although it is preferable to have the cron daemon start the runacct procedure auto- matically (see the first example), you may enter the command from the keyboard. The runacct command will run in the background, ignoring all INTERRUPT and QUIT signals (nohup), and write all standard error output (2>) to the /var/adm/acct/nite/accterr file. To restart the system accounting procedures for a specific date, enter a command similar to the following: nohup /usr/sbin/acct/runacct 0601 2>> /var/adm/acct/nite/accterr& In this example, the runacct command is executed on the first day of June (0601). The runacct process reads the /var/adm/acct/nite/statefile file to find the state from which to start. The runacct process runs in the background and ignores all INTER- RUPT and QUIT signals (nohup). The standard error output (2) is appended (>>) to the end of the file named /var/adm/acct/nite/accterr. FILES
Specifies the command path The active login/logout database file. The active process accounting database file. The active disk-usage accounting database file. The active queue (printer) accounting file. The file containing records of fees charged to users. The command and total accounting summary files. The concatenated version of the pacct files. The runacct error message file. Prevents more than one invocation of the runacct shell procedure. Contains the last date the runacct shell procedure was run. Contains the next state to process. A shell procedure containing site-dependent accounting commands. Accounting header file that defines formats for writing accounting files. RELATED INFORMATION
Commands: acct(8), acctcms(8), acctcom(8), acctcon(8), acctmerg(8), acctprc(8), fwtmp(8), wtmpconvert(8). Daemons: cron Functions: acct(2) System Administration delim off runacct(8)
All times are GMT -4. The time now is 01:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy