Results 1 to 5 of 5
I am writing a tcsh script that connects to another machine and starts a process, then gives it additional commands. However, I am not entirely sure how to do this ...
- 07-13-2011 #1Just Joined!
- Join Date
- Jul 2011
- Posts
- 3
tcsh script - find running process with grep
I am writing a tcsh script that connects to another machine and starts a process, then gives it additional commands. However, I am not entirely sure how to do this properly, as in locating the process after it has been started. Here is what I am thinking so far:
But I am unsure of how to proceed from here - and I don't know an extensive amount of shell commands.Code:ssh "<machine name>" -l <user> <start process command> ssh "<machine name>" -l <user> ps -ax | grep <process name> ...
I would appreciate any advice - am I even going in the right direction with this?
- 07-13-2011 #2
Possible, but this approach might become "spaghetti code" quite soon, because of potential use of multipe commands and escapes.
Also, it is not the best approach to open a ssh connection for each and every command. This will make it quite slow.
You could use parallel-ssh (called pssh on some distributions) and despite the name: useable even for one machine.
pssh offers you to direct the standard out and standard error of each host to an indivial file
and especially it has the --send-input flag.
With that, you can write little macros and dont need to care about extra escaping.
Like this
But tbh, I would approach that differently:Code:mkdir ~/pssh-workdir/{err,out,macros} cat >> ~/pssh-workdir/macros/test1<<'EOF' ls -la ps auwx | grep blah EOF cat >> ~/pssh-workdir/hostlist<<'EOF' <host1> <host2> EOF cat ~/pssh-workdir/macros/test1 | pssh --send-input -h ~/pssh-workdir/hostlist -o ~/pssh-workdir/out -e ~/pssh-workdir/err
- management/maintenance with Puppet
- and monitoring with Xymon
Want to ensure a daemon is running?
See this for details: Documentation | Puppet Labs - Module OrganizationCode:service { <daemon>: ensure => running }
I like that
That keeps it running, until something bad happens (syntax error in daemon config, out of disk space, hardware error, etc
So monitoring is needed. And my favourite for this is
green : Xymon - Status @ Wed Jul 13 14:27:51 2011You must always face the curtain with a bow.
- 07-14-2011 #3Just Joined!
- Join Date
- Jul 2011
- Posts
- 3
Thanks for the advice - unfortunately, due to the way the system this will be running on is set up, I can't store anything in files, create new directories, or use any external tools, like puppet or xymon.
Spaghetti code is not really a concern here, as the entire script is fairly short, and is a single strand of spaghetti anyway.
So I would appreciate it if you could please tell me what I would need to add to the code in my original post (and preferably explain how it works) in order to give the just started or long-running process a command, such as an order to do something or a kill signal.
- 08-02-2011 #4Just Joined!
- Join Date
- Jul 2011
- Posts
- 3
I still need help with this, please respond.
- 08-04-2011 #5Linux Guru
- Join Date
- May 2011
- Posts
- 1,842
Well, an order to do something is kind of ambiguous. If the process you want to control supports accepting signals then, great, just send them - you have a remote shell in. If you want to kill it, just send the kill sig to the pid,.e.g
Code:# get the pid pids=$(ssh USER@REMOTE "ps -eo pid,cmd|awk '/myprog/{print \$1}'") # kill the pid ssh USER@REMOTE kill -9 $pids


Reply With Quote
