Why commands inside bash script lost effectiveness?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why commands inside bash script lost effectiveness?
# 1  
Old 04-17-2014
Why commands inside bash script lost effectiveness?

Hi,

I have a bash script to run many system commands on CentOS machine, but I am puzzled by some commands had no effect on parent environment.

For example, I want to refresh the desktop xdg menu when some processes added or deleted items from desktop xdg menu. If I run "killall gnome-panel" directly to command line in a terminal, it'll refresh the gnome panel (killed the old panel, and restart the panel again) updated desktop xdg menu. But if I added "killall gnome-panel" to the bash script and run the script in the terminal, nothing did happen, it did not refresh the gnome-panel at all, just like it was not called.

I think that might be sub process could not affect to parent environment, but I could not find a solution to fix it . Any advice would be much appreciated.

BTW, I don't think the "killall gnome-panel" is an appropriate command to be used for refreshing or updating desktop xdg menu, appreciate if anyone know better commands to refresh or update the xdg menu.

Thank you.

Kind regards.
# 2  
Old 04-17-2014
Disclaimer: I don't use GNOME and know nothing of gnome-panel.

At the very least, show us the script, so we can rule out an error there (it may be a simple, single line, but we don't know that at this point).

Are any error messages generated? Did you check the exit status of killall?

Are you running as the same user when running the script as when invoking the command directly?

A child process cannot affect its parent's environment, but I don't think that's relevant; killall simply opens /proc and looks for matching processes.

Regards,
Alister
# 3  
Old 04-17-2014
Are you actually just running these "from a script" or are you running these from some other, separate environment like a crontab or the like? If it's run from a shell not descended from your login, it won't have your login information.
# 4  
Old 04-17-2014
Quote:
Originally Posted by Corona688
Are you actually just running these "from a script" or are you running these from some other, separate environment like a crontab or the like? If it's run from a shell not descended from your login, it won't have your login information.
You are right. The script was running from clicking a python wx button, the issue I've just figured out is there is another command needs be run before it as following script.

exec su -l ${user}
killall gnome-panel

The "exec su -l ${user}" refreshed the change of user access permission, but lets user to log into another environment where the following "killall gnome-panel" won't afffect to the current parent environment which called script.

$ update_user_id.sh

In update_user_id.sh:

exec su -l ${user}
killall gnome-panel


The question is really, whether it is possible to make the subsequent login and changes to affect to parent environment? Or there is no way to make it work?

Thank you.

Kind regards.

$ update_user_id.sh


In update_user_id.sh:


exec su -l ${user}
killall gnome-panel
# 5  
Old 04-18-2014
The environment is a list of keys and values mapped into a process' address space. kill (and killall which is a kill wrapper) does not affect it.

If you are using exec in a script, commands which follow will not execute because the exec'd command has replaced the shell.

You probably want to use su(1)'s -c option. I say "probably" because it's not clear to me what you're doing and under what circumstances you're doing it.

Regards,
Alister

Last edited by alister; 04-18-2014 at 05:46 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Saltstack commands inside bash scripts donā€™t work

In a Redhat Linux environment, I could run salt commands on the $ prompt but not inside my bash scripts. It will say command not found and the $PATH variable is exactly the same outside and inside the script. !#/usr/bin/bash echo “running”¯ salt "*" cmd.run ‘ls' exit Output:-... (8 Replies)
Discussion started by: gurudewa
8 Replies

2. Shell Programming and Scripting

Executing sed command inside a bash script

I want to run commands inside a bash script. An example is I want to pass the command in a string as regexp as an argument to the script, then run sed on the bash variable sed.sh regexp sed.sh "-i \"s/<p>//g\"" then call sed "$regexp" $fl (3 Replies)
Discussion started by: Kangol
3 Replies

3. Shell Programming and Scripting

Is it possible to change paths inside a bash script?

i have some script with some paths inside it. The idea is to some files which is on desktop copy and move to another location. Problem is that inside script is similar to this: cp test1.zip /root/help/ because I allways have another zip files, does it possible to have some input which ask me... (18 Replies)
Discussion started by: tomislav91
18 Replies

4. Shell Programming and Scripting

Expect not working inside my Bash script

I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows: #!/bin/bash HOST=$1 /usr/bin/expect -c " spawn ssh -i /root/.ssh/id_rsa root@$HOST expect -exact "Enter... (3 Replies)
Discussion started by: John Wilson
3 Replies

5. Shell Programming and Scripting

RMAN commands inside crontab shell script

Hello I'm trying to write simple script to delete archive logs for RMAN, unfortunately it's not working, I tried two way to do that: #!/bin/ksh echo "Start ....." rman target=/ << EOF RUN { delete force noprompt archivelog until time 'sysdate-10'; } EXIT; EOF echo "END ..." echo... (6 Replies)
Discussion started by: samer.odeh
6 Replies

6. Homework & Coursework Questions

brand new user!.. Lost on BASH script writing

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have just gotten into writing bash scripts for a class, part of the assignment is to read and be able to tell... (4 Replies)
Discussion started by: Byrang
4 Replies

7. UNIX for Dummies Questions & Answers

using awk inside bash script?

Hello, I'm trying to write a bash script that will query the current system time (OS X 10.6.6) and then convert the output from HH:MM:SS into time in seconds. The output of the system time command (systemsetup -gettime) is returned as: Time: HH:MM:SS so I wanted to use awk -F: to grab... (5 Replies)
Discussion started by: xaiu
5 Replies

8. Shell Programming and Scripting

Unix commands failing inside the shell script

When my script deals with large input files like 22Gb or 18 GB the basic commands like sort or join fails when run from inside the shell scripts. Can there be any specific reason for this? For e.g. sort -u -t "," -k1,1 a.csv > a.csv.uniq" sort -u -t "," -k1,1 b.csv > b.csv.uniq" The... (3 Replies)
Discussion started by: esha
3 Replies

9. Shell Programming and Scripting

How to use ftp commands inside shell script? Help please

Dears, I'm new in shell scripting and i need your help, i would like to know how can i create a script to ftp to a certain unix/linux machine/server IP address and get a file for example without user intervention? How can i force the script to use a certain username and password to access this... (4 Replies)
Discussion started by: Dendany83
4 Replies

10. Shell Programming and Scripting

bash and ksh: variable lost in loop in bash?

Hi, I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh). The goal of my script if to read a "config file" (like "ini" file), and make various report.... (2 Replies)
Discussion started by: estienne
2 Replies
Login or Register to Ask a Question