[Solved] Running user script after login.

Post here if you are a new Porteus member and you're looking for some help.
thetrickster
White ninja
White ninja
Posts: 5
Joined: 03 Oct 2012, 15:31
Location: Belarus

[Solved] Running user script after login.

Post#1 by thetrickster » 03 Oct 2012, 15:41

Hi, porteus community.
Just started using this distro after slax and cant figure out one thing.

I need to run my script just after user logs. My script prints some message and then waiting till user press "Enter" button. (Replace CD)
I enabled autologin for root in tty1 by adding following line:
c1:12345:respawn:/sbin/agetty -n -l /usr/bin/autologin 38400 tty1 linux

Now i'm trying to start my script but and it starts well but i cant get out of it (exit) by pressing ctrl+c.
I tried to run it from .bashrc and from rc.local and rd.M but can't resolve this issue.

Will be very thankful for your help.
Last edited by thetrickster on 06 Oct 2012, 10:17, edited 1 time in total.

User avatar
fanthom
Moderator Team
Moderator Team
Posts: 5666
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland
Contact:

Re: Running user script after login.

Post#2 by fanthom » 03 Oct 2012, 16:06

hi thetrickster,

try to use 'autoexec=' cheatcode, example:

Code: Select all

autoexec=telinit~3;/path/your_script
Cheers
Please add [Solved] to your thread title if the solution was found.

User avatar
Ahau
King of Docs
King of Docs
Posts: 1331
Joined: 28 Dec 2010, 15:18
Distribution: LXDE & Xfce 32/64-bit
Location: USA

Re: Running user script after login.

Post#3 by Ahau » 03 Oct 2012, 16:18

I'm having the same issue with my auto-update script: http://forum.porteus.org/viewtopic.php?f=53&t=1556

When running in text mode (autoexec=telinit~3), the script is started as a sysvinit manner, as /etc/rc.d/rc4.d/S-updatemodulename, and while it is running in this manner, it cannot be killed with Ctrl-C. If I allow the system to proceed to init 3 and I log in as root or guest, then execute the same script, it can be killed with Ctrl-C.

I"m wondering if this might have something to do with it: http://www.linuxquestions.org/questions ... ps-816782/

Perhaps an upgrade to bash 4.2 (i.e. Slackware 14, Porteus 2.0 yet to come) will help... in the mean time, I'm going to look into using 'trap'. I've not used it before so it's time I learn how :)
Please take a look at our online documentation, here. Suggestions are welcome!

thetrickster
White ninja
White ninja
Posts: 5
Joined: 03 Oct 2012, 15:31
Location: Belarus

Re: Running user script after login.

Post#4 by thetrickster » 03 Oct 2012, 16:52

Same thing.
Can't do anything - exit script or switch to another tty.
I tried empty script with one string:

Code: Select all

read -p
Not working also, but if exit with "Enter" key root shell prompt available.

thetrickster
White ninja
White ninja
Posts: 5
Joined: 03 Oct 2012, 15:31
Location: Belarus

Re: Running user script after login.

Post#5 by thetrickster » 03 Oct 2012, 16:58

I'm using only kernel, core and my own module and i do not need any GUI.

Maybe there is a way to use something instead telinit~3 and to boot console only?

User avatar
Ahau
King of Docs
King of Docs
Posts: 1331
Joined: 28 Dec 2010, 15:18
Distribution: LXDE & Xfce 32/64-bit
Location: USA

Re: Running user script after login.

Post#6 by Ahau » 03 Oct 2012, 18:10

I wasn't able to get this working properly with 'trap' or by executing a script via 'exec' instead of calling it directly. I think it does have something to do with init 4 -- If I have the script run out of /etc/rc.d/rc.S, ctrl-C will exit out of it. When I place the script anywhere in rc.M (after moving to init 4), ctrl-C fails to exit out of it.

I'm sure there is a way to force the system into init 3 instead of 4 for your custom setup, since porteus used to default to 3 (and now defaults to 4). Fanthom will know how to do this for sure...
Please take a look at our online documentation, here. Suggestions are welcome!

User avatar
fanthom
Moderator Team
Moderator Team
Posts: 5666
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland
Contact:

Re: Running user script after login.

Post#7 by fanthom » 03 Oct 2012, 20:22

the problem is a bit more complicated than i thought.

for the security reason "job control" is turned off while slackware/porteus is booting (you can observe that by adding "login -f root" at the end of rc.M script). that's why you cant break (ctrl+c) your script while it's running.
the only way to solve this issue is to let portues finish booting -> enable autologin -> run custom command through .bashrc or so.

all these must be achieved by editing /etc/inittab.

unfortunately agetty used in slackware does not support autologins (unlike mingetty for example) so you have to follow this HOWTO:
link

/etc/login.defs part can be skipped.
please also remove 'autoexec=' cheatcode as everything is controlled by inittab.

Cheers
Please add [Solved] to your thread title if the solution was found.

thetrickster
White ninja
White ninja
Posts: 5
Joined: 03 Oct 2012, 15:31
Location: Belarus

Re: Running user script after login.

Post#8 by thetrickster » 05 Oct 2012, 08:54

Thank you for your reply, but this method doesn't work.
I am already using it as i mentioned in first post and the problem still exists.
For now I'm trying to boot without telinit~3.
Then my script starting and I'm able to kill it with ctrl+c, but getting error messaged about starting display messages and error from INIT:
Id "x1" respawning to fast, disabled for 5 minutes.
If just turn off this messages some way i think it will be fine.

thetrickster
White ninja
White ninja
Posts: 5
Joined: 03 Oct 2012, 15:31
Location: Belarus

Re: Running user script after login.

Post#9 by thetrickster » 05 Oct 2012, 09:26

Well I came up with solution.
Maybe it not clean and beautiful but it works.
My script is running in text mode and i able to kill it or switch to anther tty.

So you need:
1. Enable autologin as in my first post. Method in fantoms link doesn't worked for me but maybe i done something wrong.
I already had autologin binary so i used it.
My function was

Code: Select all

int main()
{
execlp("login", "login","root",0);
}
2. Erase autoexec=telinit~3 from porteus.cfg in boot folder.
3. Comment the following line in /etc/inittab in core module.

Code: Select all

x1:4:respawn:/etc/rc.d/rc.4
4. At first i commented everything in /etc/rc.d/rc.4 and dm() function in rc.M but i think it's not needed as i commented line in inittab in item 3.

Thats done.

User avatar
fanthom
Moderator Team
Moderator Team
Posts: 5666
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland
Contact:

Re: [Solved] Running user script after login.

Post#10 by fanthom » 08 Oct 2012, 09:12

HOWTO linked by me works fine indeed (tested myself).

i have just forgotten to mention that you need to change default runlevel from '4' (default in Porteus) to '3'.
sorry about that.
Please add [Solved] to your thread title if the solution was found.

pizzar0
White ninja
White ninja
Posts: 28
Joined: 08 May 2011, 22:26
Location: Chritmas Island

Re: [Solved] Running user script after login.

Post#11 by pizzar0 » 18 Oct 2012, 17:58

@fathom
HOWTO linked by me works fine indeed (tested myself).
Really?!
By doing what you just did you have opened up every users desktop to the whole wide world. (If that was the intent then this is an "undocumented feature" - in MS lingo - as opposed to a "fix".)
Here is why....
A] More as an aside; WTF is yet more bash script doing in the kernel's pipeline where there should be nothing(!!) but C, C++ code?!?! (and as you have found out yourself you actually needed a piece for inittab to function. - Correct?!) So, that already indicates that something might not be "all fixed" here.
B] So now (with this "fix") the original shell, which calls the actual process, has no chance to spawn a new one which ***will not be over ridden*** by inittab, due to the C snippet (over ride) you have happily provided.
C] This way ***anyone*** can log into an already running (and supposedly "locked") machine, switch to a fresh tty (Ctrl Alt +Fx), ***kill any process started by the original shell*** (including any Screen Savers, Screen Locks and the likes) and simply bail back out directly into the original user's already running (open) desktop. - Would this be what you had in mind??
D] Before this "fix" one could call, let say X, with "exec" and all would be well with the world because if someone tried from a new shell to reach "your (already running) desktop, when they Ctrl +C it would just kill ***their original process*** and spawn them a new shell, presenting them with a fresh log-in prompt. Now bash has no control over it, whatsoever.
E] Hence, there is no "fix" for your "fix". (At least nothing that jumps to mind or seemingly easy to implement.) But one would be thrilled hear it if you are aware of one :-)
... and as always, it's just my 2c

p.s. At any time you get the undeniable urge to "script" into the pipeline, stop and ask yourself "what could go wrong?" - Normally the correct answer is: Everything!

User avatar
fanthom
Moderator Team
Moderator Team
Posts: 5666
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland
Contact:

Re: [Solved] Running user script after login.

Post#12 by fanthom » 18 Oct 2012, 18:33

@pizarro,

instead of wasting your time on writing a post which has nothing more than a rant you could just provide a better solution to the problem.
isn't it?
or maybe you dont have it?

EDIT:\\

tried your 'exec' solution and it didn't work for a simple reason:
job control is turned off while slackware is booting.
this is a security feature and the only solution (as far as i know) is to let the booting finish -> autologin -> start the process.

this way nothing is "opened to the whole wide world" (job control is still turned off during boot) and solution proposed by me is nothing different than normal booting to text mode -> logging in with 'root/toor' and starting the process manually.
the only difference is that everything is automated.
This way ***anyone*** can log into an already running (and supposedly "locked") machine, switch to a fresh tty (Ctrl Alt +Fx), ***kill any process started by the original shell*** (including any Screen Savers, Screen Locks and the likes) and simply bail back out directly into the original user's already running (open) desktop. - Would this be what you had in mind??
i think you have missed the whole issue:
desktop will never be started as booting finishes in text mode.
and this is what the OP was trying to achieve (autologin to console and start script).

next time please read whole thread carefully to avoid confusion.
Please add [Solved] to your thread title if the solution was found.

pizzar0
White ninja
White ninja
Posts: 28
Joined: 08 May 2011, 22:26
Location: Chritmas Island

Re: [Solved] Running user script after login.

Post#13 by pizzar0 » 18 Oct 2012, 22:04

and solution proposed by me is nothing different than normal booting to text mode -> logging in with 'root/toor' and starting the process manually.
You actually believe that? - and in the meantime your code-snippet is for what, ambiance?
And for those not so far in the back of the class, I did also mention "already running processes/users". - No?!
But hey, its your project, knock yourself out see if you manage to replace the entire linux kernel with just bash scripts. Seems like the improvement the whole world has been waiting for. How is it going so far?....

User avatar
fanthom
Moderator Team
Moderator Team
Posts: 5666
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland
Contact:

Re: [Solved] Running user script after login.

Post#14 by fanthom » 18 Oct 2012, 23:32

@pizarr0,

provide better solution or i'm locking the thread.
Please add [Solved] to your thread title if the solution was found.

pizzar0
White ninja
White ninja
Posts: 28
Joined: 08 May 2011, 22:26
Location: Chritmas Island

Re: [Solved] Running user script after login.

Post#15 by pizzar0 » 19 Oct 2012, 01:08

Sure, I'll be happy to;
Slax 7
http://www.tomas-m.com/blog/

BTW, I am, in no way, happy to see you fail but hey... Live and learn! Good luck!

Locked