[BASH] xclock/xcalc/xterm...process question?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [BASH] xclock/xcalc/xterm...process question?
# 1  
Old 03-04-2009
[BASH] xclock/xcalc/xterm...process question?

I have no idea how to do this:

Let's say the user opens an "xclock &" in one of my scripts and I don't want him to be able to re-open one with the script. How could I test that? Possibly with a message saying that "The <xclock(or w/e other process like xcalc)> is already running in the background".


I checked the ps command but I can't figure out what I could do with it.


Thanks in advance.
# 2  
Old 03-04-2009
This will get you started:
Code:
progname="xclock"
username=`id|cut -d\( -f2|cut -d\) -f1`
running=`ps -fu $username|grep "$progname"|grep -v grep`
if [ ! -z "${running}" ] ; then
    echo "$progname already running [$running]"
else
    $progname &
fi

# 3  
Old 03-05-2009
I see that progname would contain something related to xclock. Does that mean I'd have to rinse-repeat for each other application I'd like to block?
# 4  
Old 03-05-2009
You can change this:
Code:
progname="xclock"

To:
Code:
progname="$1"

And then use the script I provided as kind of a generic launcher which will take program name as input. There are multiple ways of ensuring that only one instance runs for a user like checking ps or creating lockfiles etc.etc. Modify suitably to best suit your environment / requirements. I assume you will be able to figure that out by yourself.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Question about xterm session $HOME

Hello and thanks in advance for any assistance anyone can offer me The fast & dirty question is... Could someone please tell me which file would open an xterm session into $HOME/Desktop instead of /$HOME? The longer version is.... I was reading about login scripts when I noticed my SSH... (3 Replies)
Discussion started by: bodisha
3 Replies

2. Red Hat

Xclock command not working

Hi, I am using Xming tool to open the my RHEL machine remotely in UI mode. When I use xclock command using 'root', the command works properly and I can see the clock pop-up. However, when I run the 'xclock' command using oracle user I get an error, which is shown in the attached file. Can... (6 Replies)
Discussion started by: omniok
6 Replies

3. Solaris

Xclock help

This is where I am getting stuck and I am wondering if I can get some help from the community. I log into putty with X11 forward enable echo $DISPLAY DISPLAY=localhost:10.0 export DISPLAY xclock ( I do see a clock) :) I am happy that I finally get to install Oracle 11g on solaris... (2 Replies)
Discussion started by: newborndba
2 Replies

4. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

5. Red Hat

xclock comand not found

hi rhel6 gurus i have set up a rhel6.2 db server. i have data base admins needing to connect to this rhel6 derver via reflectionx. reflectionx is set correctly but when attempting to test connectivity by 'xclock' the following message pops up : -bash:xclock; command not found. anyone out... (1 Reply)
Discussion started by: jsynodin
1 Replies

6. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

7. UNIX for Advanced & Expert Users

How to attach an xterm to a process/thread ?

Hi folks, I would like to know how to hook up an xterm to another process. Here is a high level view of what I am looking for 1. Main program starts 2. It creates an new xterm window 3. It then forks a second process & passes the xterm handle to it 4. The second process uses the second... (4 Replies)
Discussion started by: RipClaw
4 Replies

8. Shell Programming and Scripting

starting a bash session as child process to another bash session from a process

Hi I want to do something that might sound strange. I have a code that in written in C and is executed at startup (it's a custom process). It occasionally calls some bash scripts. The process doesn't have any terminal associated with it. One thing I don't know how to do is to start a... (5 Replies)
Discussion started by: alirezan
5 Replies

9. Shell Programming and Scripting

Xclock and background

Hi everyone, could you explain why am I not able to bring up xclock, or for that matter any Xtools (xcalc etc...), in the background? When I execute: xclock & This brings up the clock in the foreground, my focus is on the clock, not back in my command window. Any suggestion? ... (2 Replies)
Discussion started by: gio001
2 Replies

10. Linux

xterm font colors - configuration question?

When I telnet (ssh) over to my Fedora system, I find the colors horrible. For instance, regular files are white text, which is fine, but directories show up as dark blue which is virtually invisible against the black background). Additionally, when using vi, I find the colors great doing perl... (3 Replies)
Discussion started by: ripley
3 Replies
Login or Register to Ask a Question