LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   How can I script an autologin, automatically call kde(or simillar) and call an app (https://www.linuxquestions.org/questions/slackware-14/how-can-i-script-an-autologin-automatically-call-kde-or-simillar-and-call-an-app-525024/)

aboaventura 02-02-2007 12:25 PM

How can I script an autologin, automatically call kde(or simillar) and call an app
 
Hi all,

I have an application that should start without user interference.
We'd like to make an automatic login with an user without password, start kde and call the application. And, if it it's possible, when my application is finished, ask if shutdown the system will be done.

Can I write these instructions at rc.local, for example ?

Thanks.

wjevans_7d1@yahoo.co 02-02-2007 01:13 PM

Try it in rc.local. You might find these complications:

1. When you start kde, you'll have to figure out a way to know it's all the way up before running the application. I can't help you with that. Maybe you can time how long it normally takes kde to come up, and double that just to be sure.

2. Once you know that kde is up, don't just start the application. Wrap a script around that which (1) runs your application, and (2) asks whether the system should be shut down. Step 2 should be done so that the question is visible on the kde screen. To do that, put the asking of that question in a separate script (let's assume that the script is called fred), and run that by doing something like this:
Code:

xterm -e /bin/bash -c /fullpath/fred
Note that the -c option is for bash, and the -e option is for xterm. If you decide to give xterm any additional options, they must be before the -e; if you decide to give bash any additional options, they must be before the -c.

3. If your application is to run as anything other than root, instead of just running the application, you'll need to explicitly run it as the intended user. Since you're already root when you're running rc.local, you won't need to supply a password. Just use the sudo command:
Code:

sudo -u username /fullpath/application_name
4. Before the sudo command, you'll need to do things which login normally does for you. The two most obvious ones are cd'ing to the desired home directory, and setting environment variables. There are a whole bunch of them. It might be that not all of them are necessary, but some of the necessary ones might not be obvious. To see a list of ones which are set, log in to the same user who will be running the application (whether root or not), and
Code:

env | sort | less
Use that as a guide for which environment variables to set in your script. If you don't know whether to include a particular environment variable, I recommend you throw it in there unless you know of a good reason not to.

5. If you do everything exactly as outlined above, you'll have yet another problem: you don't want to hang out in rc.local forever while the application is running; you want it to run to completion before the system comes up. In face, you'll probably want it to run to completion before you start your application.

To make sure that it doesn't wait around for your application to exit before rc.local continues (and eventually exits), place everything described above except the starting of kde in a separate script, and call that from rc.local as follows:
Code:

/etc/rc.d/rc.startmyapplication &
The ampersand at the end of that means that control will return to rc.local almost immediately, rather than waiting for your application to run and exit.

To make sure that rc.local is effectively finished before you run your application, place all of this (except possibly the startup of kde) at the very end of your rc.local.

Obviously, you should remember to make all your scripts executable:
Code:

chmod 700 /etc/rc.d/whateverscript
At any rate, I must compliment you on your choice of Linux distributions!

Hope this helps.

aboaventura 02-02-2007 01:56 PM

Hi !

First of all, thank you very much for your support about my doubts.

I believe it will help me lot. But I will need to study and analize your post with care. I a beginner, so... :confused:

Thanks.

wjevans_7d1@yahoo.co 02-02-2007 02:42 PM

Caution: I have corrected my usage of the "sudo" command.

acummings 02-03-2007 02:59 AM

id:3:initdefault:

That line in /etc/inittab

if U change it to

id:4:initdefault:

Then it will auto load into run level 4, auto starting your default WM

if u using KDE as your default WM (desktop, whatever) then, now (after the /etc/inittab change) u logon via KDM (KDE desktop display manager)

Next, in KDE go to its control center wherein you can opt to auto logon a user (user doesn't need to enter username and password to logon) -- to opt for this, it will prompt u for super user mode or u opt for super user mode then enter the root password in order to make these changes.

al@P3box ~$ cd .kde
al@P3box ~/.kde $ pwd
/home/al/.kde
al@P3box ~/.kde $ ls | grep Auto
/Autostart

In that Autostart folder underneath the .kde folder -- any .desktop (dot_desktop) put in that folder autostarts the corresponding app

Now boots, auto logs on the user to KDE, auto starts desired app

(Do not do this at a business where you do not want other people having access to your files/data (desktop).

--
Alan.

TSquaredF 02-03-2007 07:26 AM

Alans ideas above are good, except I wouldn't use a .desktop file to start the program. I would use something like
Quote:

#!/bin/sh
/path/to/program
sudo shutdown -h now
This would allow you to automagically shutdown as you wanted. It would also require that your autologgedon user be added to the sudoers file to use shutdown. See man sudo or man sudoers.
Regards,
Bill

H_TeXMeX_H 02-03-2007 12:49 PM

Note that a bash script should almost always begin with

Code:

#!/bin/sh
NOT

Code:

#!/bin/bash
for portability reasons. /bin/sh links to whatever Bourne-compatible shell you might have installed (usually but not always /bin/bash).

TSquaredF 02-03-2007 09:46 PM

OK, I've changed my post above, but just for that post. I never use any shell except bash, & I'm sure that most newbs don't either, so /bin/bash will work for a large majority of us all the time. But we must satisfy the nitpickers.
Regards,
Bill

acummings 02-03-2007 11:00 PM

Oh, (sorry) I missed the part about the OP request to shutdown the system.

If all you want to do is autostart a few apps, then, copied from the KDE help center:

kdesktop in its turn automatically starts applications stored in $KDEHOME/Autostart. kdesktop will automatically open any files stored in this directory including documents, binary files or applications in the form of .desktop files.


KDE Internals
KSMServer

That's the relevant section where I copied from the KDE help center.

--
Alan.


All times are GMT -5. The time now is 02:18 AM.