Reset $1 variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reset $1 variable
# 1  
Old 02-11-2015
Linux Reset $1 variable

Hi all,

I'm using a scipt with one input and one output.
I'm referring to the input by $1
after executing a command line, I'm getting the output via $1.
Normally, the $1 shouldn't get the same values between the first call and the second.
Is there a solution to force my second call for $1 to get the value of $PS -efo pcpu,vsz,arg

Here is my script:
Code:
SWAPINFO="/usr/sbin/swapinfo"
PS="/usr/bin/ps"
AWK="/usr/bin/awk"
GREP="/usr/bin/grep"
SORT="/usr/bin/sort"
TAIL="/usr/bin/tail"


MYPAT="$1"
Availability=0
export UNIX95=1
VAR=$($SWAPINFO -ta | $GREP memory | $AWK ' { print $2 } ')
MYCPU=` $PS -efo pcpu,vsz,args | $GREP -v COMMAND | $GREP -v awk | $GREP "$MYPAT" | $SORT -k 1 | $TAIL -1 | $AWK -v var=$VAR -v pattern="$MYPAT" ' { print $1 } '`
echo $MYCPU


Last edited by Don Cragun; 02-11-2015 at 06:12 AM.. Reason: Fix CODE and ICODE tags.
# 2  
Old 02-11-2015
Sorry, I don't get your request.
Quote:
Normally, the $1 shouldn't get the same values between the first call and the second.
Why not? What should modify it?
Quote:
my second call for $1
In your script, there's no second call for $1.

Please rephrase your request.
# 3  
Old 02-11-2015
supose my script is called myscript.sh
in the UNIX terminal I will type
$ myscript.sh ProcessName
where ProcessName is the name of the process I want to monitor.

MYPAT=$1 will affect ProcessName to MYPAT.
In the end of the line
Code:
MYCPU=` $PS -efo pcpu,vsz,args | $GREP -v COMMAND | $GREP -v awk | $GREP "$MYPAT" | $SORT -k 1 | $TAIL -1 | $AWK -v var=$VAR -v pattern="$MYPAT" ' { print $1 } '`

Print $1 should give the value of "pcpu" in relation to
Code:
MYCPU=` $PS -efo pcpu,vsz,args


Last edited by rbatte1; 02-11-2015 at 08:25 AM.. Reason: Changed ICODE tags to just CODE tags
# 4  
Old 02-11-2015
That print $1 is a field within awk and has nothing to do with the script's $1 (shell positional parameter).
This User Gave Thanks to RudiC For This Post:
# 5  
Old 02-11-2015
In awk, $ means column. $1 means "print column 1".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Reset Password

Installed Solaris 11.3 Gnome Desktop It wouldn't let me log on at lock screen after first reboot. It finally relented and let me in after about 20 logon failures. How do I reset password now that I am in? (10 Replies)
Discussion started by: Solaris User
10 Replies

2. UNIX for Beginners Questions & Answers

Variable inside while loop got reset

hi, I am using hp unix server and not getting variable output present inside the while loop. I have tried changing the code and need to verify whether it is proper practice of code. I am expecting the output of varible RUN_FILE 3 to TRUE which i get inside the while loop. RUN_FILE 1=TRUE... (8 Replies)
Discussion started by: gowthamsoft
8 Replies

3. OS X (Apple)

Reset Password

So my dad bought an iMac from my mom, but she does not know the admin password anymore. I read on the apple forums that I should look here for help on resetting the password. The iMac runs OSX 10.6.3. I would really appreciate any help. Thanks (3 Replies)
Discussion started by: PhsycoDragon
3 Replies

4. Emergency UNIX and Linux Support

The connection was reset

Hi Folks, I have recently started Apache on my Fedora 11. I placed a working html file in the ServerRoot. I can wget and telnet from within the localhost and access the index.html. My telnet to port 80 from another machine works fine but when I try to access the web page through Firefox I... (8 Replies)
Discussion started by: jacki
8 Replies

5. UNIX for Advanced & Expert Users

Password reset

Can anyone tell me if it is possible to have cron change your password every month from an encrypted list of passwords?I have several servers I hardly ever go near but when I do the password has always expired and it takes a long time to get the administrators to reset it for me. I was thinking... (4 Replies)
Discussion started by: steadyonabix
4 Replies

6. OS X (Apple)

Permission Reset?

OSX 10.4.11 I installed an app. I am logged in as Admin. When I launch Limewire I get: You do not have permission to open the application "xxxx". How can I get around this? I tried resetting permission on the terminal and I still get it. (3 Replies)
Discussion started by: coopns
3 Replies

7. Forum Support Area for Unregistered Users & Account Problems

reset email id

please reset my email id (0 Replies)
Discussion started by: beed123
0 Replies

8. HP-UX

reset console

I have HP-UX 11i. My serial console is not responding to any input. How can I reset the console without rebooting the system? I can telnet in with no problem and system runs fine other than the console. Thanks. (2 Replies)
Discussion started by: mizzleman
2 Replies

9. UNIX for Dummies Questions & Answers

Tape Reset?????

I'm changing from SCO UNIX to Red Hat Linux. In the UNIX box when backing up my data to tape I usually do this: tape reset sleep 5 nohup tar ................... I want to know if there is a way to do "tape reset" in Red Hat Linux. (1 Reply)
Discussion started by: rrivas
1 Replies

10. UNIX for Advanced & Expert Users

System Reset

Hi: Problem: Whenever I plug-in or out a serial cable from Sun 220 Server it resets itself and gives me OK prompt. I need to use one dumb terminal for two 220s. Any suggestions or comments will be highly appreciated. (2 Replies)
Discussion started by: s_aamir
2 Replies
Login or Register to Ask a Question