Sponsored Content
Top Forums Shell Programming and Scripting Retrieving previous command in a script Post 303002675 by SkySmart on Wednesday 30th of August 2017 01:28:23 PM
Old 08-30-2017
Retrieving previous command in a script

i know from the command line, the symbol $_ is used to get the last command that was run.

however, id like to replicate this within a script.

meaning, how do i do something like this:

Code:
#!/bin/sh
ps -ef | egrep talling
StoreThisLastCommandA=$_
awk '/error/ {print $3}' /tmp/test
StoreThisLastCommandB=$_

My goal is to have the variable StoreThisLastCommandA contain
Code:
 ps -ef | egrep talling

since that is the last command ran at that point in the script.

Likewise, I want the variable StoreThisLastCommandB to contain
Code:
awk '/error/ {print $3}' /tmp/test

because, again, that is the last command kicked off at that point.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

getting the previous command

Hello all I'm on SunOS5.9 and I'm trying to make the arrow keys work as in DOS ..get the previous command , etc .. I searched this site and got an answer. I pasted the following code to my .kshrc file in my home directory...It still does not seem to work ...Am I missing anything here ? I'm... (5 Replies)
Discussion started by: luft
5 Replies

2. UNIX for Dummies Questions & Answers

Retrieving the execution time of a completed command

Hello, I am new to this forum and relatively new to unix, but hope to become an expert soon! My question is: How can I find out the execution time of a command that has already completed execution? More specifically, I launched a Python script to populate a PostgreSQL database on Suse... (2 Replies)
Discussion started by: marina
2 Replies

3. UNIX for Dummies Questions & Answers

Seeing previous command

Guys, In work we have just gotten a new HP 9000 server and I'm trying to set it up so that if I press <Up arrow> key I can see the command I typed in last(and press enter to run it again). Can anyone advise how to set this up. One friend suggested I touch a file called .toucheditXXXX (I cant... (4 Replies)
Discussion started by: JackieChan
4 Replies

4. UNIX for Advanced & Expert Users

Previous Command

We have a Solaris Server and I am acessing it through telnet to run various commands for my data validation like GREP, SED, AWK etc. My requirement is how do i use the previous command that was executed. I tried the option 'ESC' and then 'k'. It displays the characters like '^[[A' etc. How do I... (0 Replies)
Discussion started by: vskr72
0 Replies

5. Shell Programming and Scripting

Previous Command

We have a Solaris Server and I am acessing it through telnet to run various commands for my data validation like GREP, SED, AWK etc. My requirement is how do i use the previous command that was executed. I tried the option 'ESC' and then 'k'. It displays the characters like '^[[A' etc. How do I... (1 Reply)
Discussion started by: vskr72
1 Replies

6. UNIX for Dummies Questions & Answers

Previous Command

We have a Solaris Server and I am acessing it through telnet to run various commands for my data validation like GREP, SED, AWK etc. My requirement is how do i use the previous command that was executed. I tried the option 'ESC' and then 'k'. It displays the characters like '^[[A' etc. How do I... (2 Replies)
Discussion started by: vskr72
2 Replies

7. HP-UX

Retrieving the full command

Hi All, I would like to retrieve the whole command that got executed for a running process rather than a truncated string, as a result of running ps -ef on HP-UX. Please help. TIA (1 Reply)
Discussion started by: trocadero
1 Replies

8. HP-UX

Previous command

Hi, i would like to retrieve (only retrieve, not execute) a previous command which i executed on the command prompt. I tried the 'up arrow' key, but its not working. Instead,it showed me some funny characters. I searched around and i found the way to do it was using the way below. Several... (5 Replies)
Discussion started by: new2ss
5 Replies

9. UNIX for Advanced & Expert Users

Retrieving command line arguments of a particular PID

hi The "ps" command shows the command line arguments of running processes: $ /bin/ps -o pid,args -e .... 26031 pico /tmp/crontab2KaG1Y 596 /usr/lib/sendmail -bd -q15m 9955 xterm -n 1 -sb -sl 800 -g 80+70+70 2627 /usr/sbin/snmpd -Lsd -Lf /dev/null -p /var/run/snmpd -a 1691 .... I... (2 Replies)
Discussion started by: Andrewkl
2 Replies

10. Shell Programming and Scripting

Retrieving values from tab-delimited file in unix script

Hi I am trying to retrieve values from a tab-delimited file.I am using while read record value=`echo $record | cut -f12` done Where 12 is the column no i want retieve and record is one line of the file. But it is returning the full record. Plz help (4 Replies)
Discussion started by: akashtcs
4 Replies
uudemon(4)						     Kernel Interfaces Manual							uudemon(4)

NAME
uudemon.admin, uudemon.cleanu, uudemon.hour, uudemon.poll - Administrative shell scripts for polling remote systems, cleaning up spool directories, reporting status to the system administrator, and routine invocations of the uuxqt and uusched daemons SYNOPSIS
These shell scripts reside in the following directory: /usr/lib/uucp DESCRIPTION
All the scripts can be run from the command line or can be run automatically by the cron daemon. To automatically run the scripts, remove the comment character (#) from the beginning of the relevant line in the /var/spool/cron/crontabs/uucp file. This script reports status to the system administrator. It issues the uustat command to find out the status of uucp jobs. It mails the results to the uucp login ID. The script may be modified to send mail to any login ID such as the uucp administrative login ID (uucpa) or root. This script cleans up the /var/spool/uucp and /var/spool/uucppublic directories by running the uucleanup command. The uucleanup com- mand is run with the following parameters: -C7, -D7, X2, -o2, -W1. This script runs the uusched and uuxqt daemons in the background. This script polls the systems listed in the /usr/lib/uucp/Poll file. The uudemon.poll script should be scheduled before the uudemon.hour script. This allows uudemon.poll to create any command files before cron runs the uudemon.hour script. FILES
Contains the uudemon.admin, uudemon.cleanu, uudemon.hour and uudemon.poll files. Contains the uucp file. RELATED INFORMATION
Commands: cron(8), uucleanup(8), uusched(8), uuxqt(1) Files: /usr/lib/uucp delim off uudemon(4)
All times are GMT -4. The time now is 04:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy