Script not returning what I am expecting


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Script not returning what I am expecting
# 1  
Old 03-27-2017
Script not returning what I am expecting

Hi there

I am trying to create a script where I am checking the process is being run by the correct user, when I go to run the script it is not returning what I am expecting and I am not 100% sure why!!!

First off I have determined what the process user should be at the top of the script
Code:
enterprise_manager_user="casupport"

Then I have ran the process as I would normally in the command line
Code:
em_process_user=`ps -efl | grep 'Introscope_Enterprise_Manager.lax' | grep -v grep| awk '{print $3}'`

- An example below on the return from that:
Code:
[casupport@wycvlapph048 enterprisemanager]$ ps -efl | grep 'Introscope_Enterprise_Manager.lax' | grep -v grep| awk '{print $3}'
root
[casupport@wycvlapph048 enterprisemanager]$

I have then wrote my script saying if the em_process_user = enterprise_manager_user then do this if not do this. I am expecting it to return as root but as determined at the top of the script I have said enterprise_manager_user should = user casupport so should alert however it doesn't
Code:
if [ "$em_process_user"="$enterprise_manager_user" ]
then
        em_process_user_flag=0
else
        em_process_user_flag=1
fi

echo $em_process_user_flag
echo $em_process_user

When I execute the script it comes with the following:
Code:
[casupport@wycvlapph048 enterprisemanager]$ ./test.sh
0
root

Surely it should come back as 1?

Thanks in advance for any help!

Last edited by RudiC; 03-27-2017 at 08:18 AM..
# 2  
Old 03-27-2017
Without digging deeper, on first sight there's two spaces missing around the = sign in the test condition.

While we're at it, did you consider using
Code:
ps -efl | awk '/Introscope_Enterprise_Manager.lax/ {print $3}'

in lieu of the looong grepping chain?
# 3  
Old 03-27-2017
Hi RudiC

Thanks the spaces seemed to fix the issue! Can't believe something so small caused the problem!

Thanks again
# 4  
Old 03-29-2017
Have you considered using pgrep?
Code:
pgrep -u "$enterprise_manager_user" 'Introscope_Enterprise_Manager.lax'
pgrep -v -u "$enterprise_manager_user" 'Introscope_Enterprise_Manager.lax'

Assuming that Introscope_Enterprise_Manager.lax is the name of the process you are looking for, the first pgrep will return all PIDs of those processes being run by the required user, while the second one will return all PIDs not being run by that user.

Andrew
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect script not expecting the password prompt

I have a script that does an SSH into a remote node. It should expect the prompt and send the password. #!/usr/bin/expect set user ; set pass ; spawn ssh $user@E-Internal expect { -re "RSA key fingerprint" {send "yes\r"} timeout... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

2. Shell Programming and Scripting

Expect script to suspend expecting for a time period.

I have a simple Expect script to power a system on and off in an endless loop looking for an ERROR message at which point the script should exit. But I need to skip the first 60 seconds after each power on or off and not exit if there are ERROR messages during that time. I thought I could use... (0 Replies)
Discussion started by: David_Gilhooly
0 Replies

3. UNIX for Dummies Questions & Answers

Not returning from a sub script?

My problem in brief is that I execute a script from another script and I can not pick up the return code from that script, or otherwise I am not returning from that script. I have an echo in the executed script and we get a response code of 0 and exit that script with the return code. I then try to... (1 Reply)
Discussion started by: Charles Swart
1 Replies

4. Shell Programming and Scripting

Script returning 0

hello i write a script which calculate free space but he always is 0 thats wrong with my script? getFileSystemPerformanceData() { if ; then if grep -q "Ubuntu" /etc/issue ; then CMD="df -lP | grep -v "\/home" | grep -v "\/dev/mapper/VolGroup-lv_root"" elif grep... (5 Replies)
Discussion started by: donatas1234
5 Replies

5. Shell Programming and Scripting

Returning to shell from previous script

Found myself stuck on this seemingly trivial issue. I have this script which call other shell files to do their deeds. The shell files in turn call some other programs as well. My problem is that in two of these shell files, the control doesnt return to next command in script unless the Enter key... (2 Replies)
Discussion started by: DoesntMatter
2 Replies

6. UNIX for Dummies Questions & Answers

grep, expecting 1 result, getting more

Hi Please take a look below, I'm grepping for /app/oracle and would like explicitly that result and not /app/oracle/admin as well. # cat /tmp/fs.list /app/oracle /app/oracle/admin # cat /tmp/fs.list | grep -w "/app/oracle" /app/oracle /app/oracle/admin (3 Replies)
Discussion started by: s1ckle
3 Replies

7. Solaris

expecting answers for these questions?

hi all plese clarify me in the following area. 1. What is the default NFS version in solaris 5.10. If it is 3, then why it asks me to specify "-o vers=3" keyword while i am mounting a share from a RHEL 5.1 Server? 2. Can someone give the link to download packages for accessing "ntfs"... (4 Replies)
Discussion started by: kingston
4 Replies

8. UNIX for Advanced & Expert Users

Returning a value to a calling script

Hi. I'm trying to call a script named checkForFile.sh from within my main script named master.sh. In checkForFile.sh I want to set a value to the variable fileExist, but then I want to reference the value in the master.sh script. Whenever I attempt this the echo statement is just blank. ... (5 Replies)
Discussion started by: buechler66
5 Replies

9. Shell Programming and Scripting

returning to the parent shell after invoking a script within a script

Hi everybody, I have a script in which I'm invoking another script which runs in a subshell. after the script is executed I want to return to the parent shell as some variables are set. However i'm unable to return to my original shell as the script which i'm calling inside is invoked in... (5 Replies)
Discussion started by: gurukottur
5 Replies

10. Shell Programming and Scripting

Returning to begining of a script

Dear all, When i ask a question in my script if the answer is not correct i need to goback to the begning of the script and ask the question again. ex - What is your name ? saman Name is not correct ...try again What is the name ? Nimal Thank you.... (2 Replies)
Discussion started by: Nayanajith
2 Replies
Login or Register to Ask a Question