Poweroff Computer once a process is completed

Hi everyone,

            I am using OpenSUSE 12.3 with XFCE DE.Now I am trying to run Terminal Server Client at startup so that I can get Windows login screen directly and when I close that connection the system should automatically shut Down.I have done the following 

1.Created a script with following command and added it in the startup applications

tsclient -s win7 && /sbin/poweroff.

But it’s not working.Any ideas?

Thanks in advance.

I presume “startup applications” means after you logged in. In this case if you log in as normal (non root) user you are not allowed to run /sbin/poweroff. You may want to look at using sudo to run it.

Or use “systemctl poweroff” instead of “/sbin/poweroff”.
This should even work as a normal user (with the default polkit settings).

Actually the second command is not at all getting executed.My requirement is I start a connection with tsclient -s win7 and when I click cancel on the login page or log off the session it should shut down immediately without showing desktop

Well, the && operator only executes the second command when the first one exits successfully (return code 0).
See here f.e.: http://stackoverflow.com/questions/4510640/command-line-what-is-the-purpose-of

Put the second command in a new line (without &&) and it should be executed in any case… (or use ; as separator)

Actually the first command should get executed and if it fails to execute for whatever reason or cancelled by the user then the computer should shut down automatically.

On 2013-09-28 17:26, nishanth9042 wrote:
>
> Actually the second command is not at all getting executed.My
> requirement is I start a connection with tsclient -s win7 and when I
> click cancel on the login page or log off the session it should shut
> down immediately without showing desktop

Try “;”


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

when I try this “tsclient -s win7;systemctl poweroff” The computer gets shut down once the first command is executed.But I want the computer to shut down only when the first command is terminated or cancelled by the user or after the successful completion of first command.

Then || should be what you need. Have a look at that page I linked to.

I have tried that but the computer is getting shut down immediately after the first command is executed.

OK, so your actual problem is that tsclient returns immediately to the calling shell.
So you would have to wait until the process actually exits.

Something like this maybe? (not sure if that works without change)

until  `grep tsclient $processes`  -eq 1 ]; do
   sleep 10
   processes=`ps ux`
done

Or maybe use startproc/checkproc (see the corresponding man pages).

I will study that tomorrow and get back to you.

Instead of tsclient I am using commandline options of rdesktop and it’s working fine now.