Results 1 to 4 of 4

Thread: Wanted: Bash program idea, or application suggestion

  1. #1
    Senior Member registered user
    Join Date
    May 2006
    Location
    Columbia, Maryland USA
    Posts
    1,631

    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.

  2. #2
    Senior Member registered user
    Join Date
    Feb 2010
    Posts
    512
    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?

  3. #3
    Senior Member registered user
    Join Date
    May 2006
    Location
    Columbia, Maryland USA
    Posts
    1,631
    .
    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.

  4. #4
    Senior Member registered user
    Join Date
    May 2006
    Location
    Columbia, Maryland USA
    Posts
    1,631
    .
    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
  •  


IBM System x3100 M5 Intel Xeon E3-1271 v3 3.6GHz 8GB RAM NO HDD NO OS Good picture

IBM System x3100 M5 Intel Xeon E3-1271 v3 3.6GHz 8GB RAM NO HDD NO OS Good

$129.99



IBM S822LC 8335-GCA Power 8 2U Server 2xPower8 8core/64t 128GB RAM Tested picture

IBM S822LC 8335-GCA Power 8 2U Server 2xPower8 8core/64t 128GB RAM Tested

$695.00



IBM Power 720 picture

IBM Power 720

$500.00



IBM 8231-E2C Power p730 Server, 3.55GHz 16 core, 2 x EPC3, PowerVM express picture

IBM 8231-E2C Power p730 Server, 3.55GHz 16 core, 2 x EPC3, PowerVM express

$595.00



Lenovo IBM System x3250 M6 XEON e3-1220v5 3.00GHZ 32GB RAM Server TESTED picture

Lenovo IBM System x3250 M6 XEON e3-1220v5 3.00GHZ 32GB RAM Server TESTED

$99.99



IBM System X3100 M5 (PN: 5457-AC1) Server picture

IBM System X3100 M5 (PN: 5457-AC1) Server

$199.99



8247-22L IBM Power8 S822L Server 2x 10Core 3.4GHz CPU 512GB  RAM Dual Power picture

8247-22L IBM Power8 S822L Server 2x 10Core 3.4GHz CPU 512GB  RAM Dual Power

$1299.99



IBM 8203-E4A pSeries 520 6-Bay Server System Power6 2 Core 4.2GHz 4GB No HD picture

IBM 8203-E4A pSeries 520 6-Bay Server System Power6 2 Core 4.2GHz 4GB No HD

$240.00



LOT OF 3: IBM System x3650 M3 Servers~Intel Xeon 5140 @ 2.33 GHz~4GB~5x 72GB SAS picture

LOT OF 3: IBM System x3650 M3 Servers~Intel Xeon 5140 @ 2.33 GHz~4GB~5x 72GB SAS

$399.99



Lenovo IBM X3650 2x Intel Xeon  E5-2620 v4 2.1GHz 128GB RAM NO HDD NO OS Good picture

Lenovo IBM X3650 2x Intel Xeon E5-2620 v4 2.1GHz 128GB RAM NO HDD NO OS Good

$199.99