Help with detaching the screen programmatically


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Help with detaching the screen programmatically
# 1  
Old 01-17-2014
Help with detaching the screen programmatically

Hi,

I am using screen utility for protecting from ssh disconnects.
My process flow i ssomething like :

a) I start screen from my desktop terminl.

b)In the screen session, i ssh to one host and execute a command

c)Once the above command is completed,i would like to exit via ctr-a or ctrl-d and send a mail to myself.

Currently, i try
Code:
command_in_remote_host;logout ;echo "it's done"|mail -s "Completed" $USER@domain.com
command_in_remote_host;exit ;echo "it's done"|mail -s "Completed" $USER@domain.com

But, the last command is not getting executed after the ssh is disconnected.

Is there any way i can programmatically simulate ctrl-a or ctrl-d , so that it can detach and send the mail?

Please advise.

Thanks
# 2  
Old 01-17-2014
This is flawed in several ways:
1) your process flow does NOT protect command_in_remote_host from ssh disconnects!
2) after exit or logout there is no shell to process the other commands.

You have to start the screen utility on the remote host. The commands you execute there will keep running regardless of disconnects.
Your flow should look like this:
a) ssh to host from your desktop terminal
b) start screen on remote host
c) start command in screen session and send notification.

The correct sequence of commands:
Code:
command_in_remote_host; echo "it's done"|mail -s "Completed" $USER@domain.com ; exit


Last edited by cero; 01-17-2014 at 08:17 AM..
# 3  
Old 01-17-2014
Hi,

Actually, there is neither screen nor mail/mailx present in the remote host. Hence I started screen from local desktop.

---------- Post updated at 09:04 PM ---------- Previous update was at 06:28 PM ----------

If i press ctrl-a or ctrl-d manually instead of logout/exit as second, then it works fine.
But, i don't see a way to implement programatically ctrl-a or ctrl-d in a shell script.
# 4  
Old 01-17-2014
If there is no screen utility on the remote host you can use nohup instead. It does not offer a virtual terminal like screen but protects the command you started on the remote host from beeing killed when you lose connection.
Without a mailer on the remote host you could use the mailer on your local machine when your ssh-session terminates (something like ssh remote_host "nohup command_on_remote_host"; echo "it's done"|mail -s "Completed" $USER@domain.com), but I do not think that makes much sense because you'd receive the mail when the ssh-session quits for any reason - disconnects included.
# 5  
Old 01-17-2014
I would like to receive the mail only after the command executed in the remote host ends.so, if I use nohup then I will receive the mail immediately
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

How to programmatically reset a users password.?

Hello all, I have a small C++ app for my solaris admins. I need to set it up so they can reset a users password. The admin does not have the old password. How can I reset a users password to a temp password either using passwd or PAM? I need to do this from within my C++ app. I have searched... (3 Replies)
Discussion started by: ChickenPox
3 Replies

2. Shell Programming and Scripting

how to programmatically generate makefile variable

I make to parse the release version from a text file and set the release version label into a Makefile variable. I tried: VERSION := `grep vsn s1db.app|sed -e s/*\"// -e s/\"*//` but looks like make, unlike shell, literally just take the entire `grep ...` as the variable value. Then I tried... (3 Replies)
Discussion started by: benkial
3 Replies

3. UNIX for Advanced & Expert Users

How to get DHCP address change event notification programmatically?

Hello Experts, I am working on a software that has network client-server architecture. I need to have a mechanism that notifies me upon change of dhcp address change locally or at remote machine. Windows have IP Helper APIs to get address change notification. Is there something similar in Unix?... (3 Replies)
Discussion started by: GajendraSharma
3 Replies

4. UNIX Desktop Questions & Answers

resize multiple xclients (xterms) on command line or programmatically?

Is there a way to resize x clients after they're started either on the command line or programmatically? I'm using Cygwin and typically start my root window, wm, and four xterms. By the end of the day they're all over the place with different sizes. I'd like to be able to enter a single command... (0 Replies)
Discussion started by: gctaylor
0 Replies

5. Programming

is it SUSE or RHEL or Debian. How to detect programmatically?

Hi Gurus, I want to programmatically detect what Linux flavour I have in my m/c, detailed OS-name and its version, e.g. is it RHEL, SUSE, Debian etc. ---------------------------------------------------------------- Flavour OS-Nname version... (4 Replies)
Discussion started by: krishnamurthig
4 Replies

6. Programming

Check the Disk usage Programmatically

Hi all, Do we have anyway to get the freediskspace for within a C program? I need functionality similar to 'df -h' -> which gives the % of utilization... Otherwise, if we go and use 'system ("df -h /home/myhome/")', do we have any way of capturing the output into a string and parse the... (2 Replies)
Discussion started by: SriSri
2 Replies

7. Programming

how to find usb ports programmatically

I need to find out where a usb flash memory drive is mounted. I have used prtconf and iostat to find the information and then used popen to parse the information to find what i need. I am wondering if there are some generic functions such as ddi_ or usb_ that i can use to find such info. I would... (1 Reply)
Discussion started by: jtcoelho
1 Replies

8. Solaris

Modify Style Manager programmatically

My Java application runs on SunOS 5.8. Our use of a 3rd party class requires us to modify the Style Manager-Window setting "Allow Primary Windows On Top" - the default for this is on, we need to turn it off. Is there any way for our application, or our installation, to modify this setting? We... (0 Replies)
Discussion started by: ped52
0 Replies

9. UNIX for Dummies Questions & Answers

Detaching file

How do I detach an attachment using mailx in a script? I haven't a clue vGnp (1 Reply)
Discussion started by: vGnp
1 Replies
Login or Register to Ask a Question