-
Senior Member
registered user
Wanted: Bash program idea, or application suggestion
.
I would like to create a small bash program that would
monitor my keystroke activity and if no keystrokes are noted
within a fixed small time, then any currently active
internet connection would be disconnected.
I currently use a Knoppix LiveUSB and wifi via a broadband router
with network connections handled by NetworkManager.
If there's 'an app for this' already, then that might also serve.
Thanks in advance.
-
Senior Member
registered user
Hi utu, I do not have a bash script for you, but I have got some suggestions. First of all, you can disable and enable the network from the commandline by using the commands
Code:
nmcli networking off
and
Code:
nmcli networking on
I think the task is similar to a screensaver because in both cases user inactivity starts a process. I read about a user who wanted to download torrents while the screensaver is active. His or her solution was to ask dbus whether the screensaver was active. He or she used the Gnomedesktop environment. Later I read the solution has to be modified if KDE is used instead of Gnome. Since xscreensaver does not seem to use dbus I think you should try to find out if power management provides an interface to run one shell script on times of user inactivity and another if the user is active again. The absence of keyboard events should start a bash script, but what about mouse events? How long is a 'small time'? Do you intend to reconnect to the network if there is any keystroke activity again?
-
Senior Member
registered user
.
Thanks for your responses, klaus2008.
nmcli is probably part of the solution; I'll study up on that.
I should have indicated keyboard and/or mouse events as an indication or
lack of user presence or attention to internet events.
I think 'a small time' might be some random number between 15 and 30 minutes
as a starting point.
If I know I'm not going to use Knoppix for a while, I manually disconnect.
If I'm interrupted, I might forget to do this; I'd like Linux to disconnect
automatically, if need be. Solution need not consider re-connect, since that's
easy enough to do manually with the NM panel applet.
You can't underestimate my programming prowess. At most I may be able to
figure out a line of bash script. I wouldn't have a prayer with C/C+/or C++
source, even if I had it to look at.
-
Senior Member
registered user
.
Two other building blocks seem to be
Code:
xscreensaver-command -watch
and the following perl program, which tracks the output of the -watch command
and reacts accordingly:
Code:
#!/usr/bin/perl
my $blanked = 0;
open (IN, "xscreensaver-command -watch |");
while (<IN>) {
if (m/^(BLANK|LOCK)/) {
if (!$blanked) {
# **** action to take when screensaver starts ****
$blanked = 1;
}
} elsif (m/^UNBLANK/) {
# **** action (if any) to take when screensaver is reset ****
$blanked = 0;
}
}
I don't think perl should be necessary, and there is probably a simpler
bash equivalent that would suffice.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
![Genuine Apple OEM 60W Magsafe Charger / AC Adapter for A1278 MacBook Pro Air picture](/store/img/g/SkAAAOSwbbFmMWbp/s-l225/Genuine-Apple-OEM-60W-Magsafe-Charger-AC-Adapter-f.jpg)
Genuine Apple OEM 60W Magsafe Charger / AC Adapter for A1278 MacBook Pro Air
$7.99
![Apple 30W USB-C Charger OEM Original Power Adapter For 2018+ Macbook Air picture](/store/img/g/hMAAAOSw3Qhmado9/s-l225/Apple-30W-USB-C-Charger-OEM-Original-Power-Adapter.jpg)
Apple 30W USB-C Charger OEM Original Power Adapter For 2018+ Macbook Air
$23.99
![Genuine OEM Apple USB-C type c to MagSafe 3 Cable 2 M- MLYV3AM/A picture](/store/img/g/N6EAAOSwWOFk3cj-/s-l225/Genuine-OEM-Apple-USB-C-type-c-to-MagSafe-3-Cable-.jpg)
Genuine OEM Apple USB-C type c to MagSafe 3 Cable 2 M- MLYV3AM/A
$22.95
![Genuine OEM Apple 30W USB-C Power Adapter Charger 2m Cable iPhone 15, iPad Pro picture](/store/img/g/P-sAAOSwCF5mYd-Y/s-l225/Genuine-OEM-Apple-30W-USB-C-Power-Adapter-Charger-.jpg)
Genuine OEM Apple 30W USB-C Power Adapter Charger 2m Cable iPhone 15, iPad Pro
$27.00
![Genuine Original OEM APPLE Thunderbolt Cable 2M MC913ZM/A MD861LL/A White 6.5ft picture](/store/img/g/gNQAAOSw01djniha/s-l225/Genuine-Original-OEM-APPLE-Thunderbolt-Cable-2M-MC.jpg)
Genuine Original OEM APPLE Thunderbolt Cable 2M MC913ZM/A MD861LL/A White 6.5ft
$18.50
![Genuine OEM Apple 45W MagSafe 2 Charger for MacBook Air / Pro TESTED - WORKING- picture](/store/img/g/G0gAAOSwv3Vjwc4C/s-l225/Genuine-OEM-Apple-45W-MagSafe-2-Charger-for-MacBoo.jpg)
Genuine OEM Apple 45W MagSafe 2 Charger for MacBook Air / Pro TESTED - WORKING-
$8.93
![Genuine Apple A1882 30W USB-C Power Adapter Apple OEM CHARGER picture](/store/img/g/BC0AAOSwILlmHZ7j/s-l225/Genuine-Apple-A1882-30W-USB-C-Power-Adapter-Apple-.jpg)
Genuine Apple A1882 30W USB-C Power Adapter Apple OEM CHARGER
$20.89
![Genuine OEM Apple 85W MagSafe 2 Charger for MacBook Pro / Air TESTED - Apple-- picture](/store/img/g/GuoAAOSwbSJkeeso/s-l225/Genuine-OEM-Apple-85W-MagSafe-2-Charger-for-MacBoo.jpg)
Genuine OEM Apple 85W MagSafe 2 Charger for MacBook Pro / Air TESTED - Apple--
$9.79
![Apple OEM QHD IPS LCD Screen Assembly for 16](/store/img/g/dFkAAOSw1D9jLPM1/s-l225/Apple-OEM-QHD-IPS-LCD-Screen-Assembly-for-16-MacBo.jpg)
Apple OEM QHD IPS LCD Screen Assembly for 16" MacBook Pro A2141 2019/20 Display
$299.99
![OEM 45W MagSafe 2 T-Tip Power Adapter Charger for MacBook Air 11''13](/store/img/g/TwAAAOSwq7tmNAfA/s-l225/OEM-45W-MagSafe-2-T-Tip-Power-Adapter-Charger-for-.jpg)
OEM 45W MagSafe 2 T-Tip Power Adapter Charger for MacBook Air 11''13"A1465 A1436
$7.49