You are not logged in.
Hello !
I'm trying to get the screenlock and keylogger aplication to work together, as in when I execute a simple bash script, the processes would go like this:
1.) start keylogging process (record whatever keys are pressed)
2.) lock screen and wait for user password
3.) after having entered the correct password, unlock screen and stop keylogging
4.) display keylog file in terminal
For locking the screen I am using i3lock, which is a modified version of slock. http://aur.archlinux.org/packages.php?ID=26090
For logging keypresses I am using logkeys. http://aur.archlinux.org/packages.php?ID=37748
(both are from the AUR)
i3lock obviously waits for the user password and Enter following it to unlock the screen. But I can't figure out how to make bash wait for i3lock to successfully unlock the screen and only then stop the keylogging process.
I tried doing it with read and echo commands, so that the bash script itself would wait for a specific keysequence (eg. a password) to continue executing the lines. And I would obviously make this "custom keysequence" the same as my user password, to make bash stop the keylogging process as soon as the screen got unlocked.
But I cannot figure out how to make bash wait for a SPECIFIC sequence. waiting for any keypress is not an option, as the whole idea is to record wheter someone tried to unlock the screen without my permission.
Here's what I have so far:
#!/bin/bash
sudo logkeys -s --output=/home/ufokatarn/.keylog #command to start keylogging and output to a specific file
i3lock -i -c 000000 #lock the screen and make it black
sudo logkeys -k #stop keylogging
sudo nano /home/ufokatarn/.keylog #display the logfile
The logkeys process needs to be run as root so I just added its executable to visudo as a NOPASSWD option.
Thank you for any clues and help you can give me.
Regards,
UFOKatarn
Last edited by UFOKatarn (2010-09-19 11:48:27)
Offline
I don't know if this will answer your question, but there is the 'wait' command of bash which waits for the termination of one or several processes.
You could insert that command after the 'i3lock' line. The process 'i3lock' should be a child process of the script, so the 'wait' command should not need an argument :
wait [n ...]
...
If n is not given, all currently active child processes are waited for, and the return status is zero.
Offline
Yea, wait is probably what you want. Here are some more specific examples.
Offline
Wow !
Thanks for the fast replies .
After having read some more about "wait", I tried making the script like this:
#!/bin/bash
sudo logkeys -s --output=/home/ufokatarn/.keylog
i3lock -c 000000
wait
sudo logkeys -k
but it didn't wait for i3lock to finish.
So I'm guessing that maybe i3lock spawns its own child process which then in turn waits for the user to enter the correct password and unlock the screen long after i3lock itselft has stopped.
Therefore, the logkeys -k command (kill keylogging) immediately got executed as soon as the screen got locked.
So I did some more research and prepared the script like this:
#!/bin/bash
sudo logkeys -s --output=/home/ufokatarn/.keylog
(
/home/ufokatarn/.screenlock -verbose $@
wait
)
sudo logkeys -k
and the "/home/ufokatarn/.screenlock" file contains the following code:
#!/bin/bash
i3lock -c 000000
And it still doesn't wait for i3lock . Hmmm...
Does anyone have any idea as to how to tell "wait" to wait for a grandchild process or how to get the process ID of the grandchild process after it started, so that one could make "wait" hals the script until that specific process has ended?
Thank you once again,
UFOKatarn
Offline
I don't know exactly how i3lock functions, but you can try to see what processes are activated by it with, for example :
i3lock -c 000000
ps -ef >afilesomewhere
then after entering the password, look what processes are present in 'afilesomewhere' which contains the output of the ps command.
You can also look at the 'jobs' command of bash, to see if it can be useful for your problem.
Offline
It seems that i3lock "escapes" from the shell (its PPID will become 1!) immediately after launch. Wait works only for processes which are the subprocesses of the same shell, so it won't work in this case. This soultion should work:
#!/bin/bash
sudo logkeys -s --output=/home/ufokatarn/.keylog
i3lock -c 000000
while pgrep i3lock &> /dev/null; do
sleep 1
done
sudo logkeys -k
sudo nano /home/ufokatarn/.keylog
“First principle, Clarice. Simplicity” – Dr. Hannibal Lecter
Offline
Thank you both very much for this info !
I've been away for a while so I haven't been able to access the forums.
As I got home, I immediately tried both scripts:
berbae: I tried your script but the output didn't tell me much. As you probably have figured out by now, I'm still a Linux rookie.
barto: That did it ^.^! It runs perfectly.
Thank you both for your wonderful help .
And by the way, for anyone interested:
I couldn't figure out how to make a script start in a terminal window if the script itself hasn't been run from inside the terminal. More specifically I wanted the make a keyboard shortcut start a script in a terminal WINDOW.
One just does it like this:
terminal -e /path/to/your/script
Regards to all.
--Marking the topic as SOLVED.--
Last edited by UFOKatarn (2010-09-19 11:46:37)
Offline