Posts tagged “Scripts”

Bash script for pushing files and folders through adb

I have made a script for pushing files and folders through adb to the SDcard of an Android device. This can be used in combination with nautilus for right-clicking on folders to push it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Script for pushing files and folders through adb.
# Can also be used without nautilus.
# Feel free to edit and distribute as much as you want.
 
# if you want dialogs set dialog_enable=1 else dialog_enable=0
dialog_enable=1
 
# Write the entire path to adb here
adbPath="/home/tomasz/AndroidSDK/tools/adb"
 
function dialogs {
        if [ $dialog_enable = 1 ]; then
                if [ -e "/usr/bin/gdialog" ]; then
                        gdialog --title "adb push" --msgbox "$1" 200 200
                elif [ -e "/usr/bin/Xdialog" ]; then
                        Xdialog --title "adb push" --msgbox "$1" 0 0
                else
                        echo "No dialog program present"
                fi
        fi
}
 
if [ $# -ne 1 ]; then    # If arguments not equal 1, complain!
        echo "Usage - $0 file"
        echo "or - $0 directory"
        exit 1
fi
 
if [ -d "$1" ]; then
        $adbPath shell mkdir "/sdcard/`basename "$1"`"  # Create the directory on SDcard
        $adbPath push "$1" "/sdcard/`basename "$1"`"    # Push files in the folder to folder on SDcard
        dialogs "Folder $1 was pushed"
elif [ -e "$1" ]; then
        $adbPath push "$1" /sdcard/    # Push single file to SDcard
        dialogs "$1 was pushed"
else
        echo "Gurumeditation!"    # Oops!
fi


Download the script by using this link: http://ostebaronen.dk/android/adbpush.sh

In order to have it in your right-click menu in Nautilus place the script in: ~/.gnome2/nautilus-scripts/ and run chmod u+x ~/.gnome2/nautilus-scripts/. Now you should see the script in your right click menu under scripts in Nautilus.

Back light keys on IBM/Lenovo Thinkpad X60t

I just got back light keys to work on my Thinkpad X60t. This is actually pretty easy. If I just had read the documentation for thinkpad_acpi before I would have known.

Anyways lets get to it.

First we need to modprobe thinkpad_acpi with some arguments, otherwise the back light Fn-key combo will not show up as acpi events, and then we will not be able to control the back light.


modprobe thinkpad_acpi brightness_enable=1 hotkey=enable,0xffffff

You probably want to do that on every boot, in gentoo you do that by adding the following to /etc/conf.d/modules:


modules_2_6="${modules_2_6} thinkpad_acpi"
module_thinkpad_acpi_args_2_6="brightness_enable=1 hotkey=enable,0xffffff"

When that is done we can start grabbing some events with acpi_listen, mine looks like this:


tomasz@arcadia ~ $ acpi_listen
ibm/hotkey HKEY 00000080 00001011
ibm/hotkey HKEY 00000080 00001010

First one is for down second for up.

Now we know this we can make some files for acpid to react on when we push the Fn-key combo for either back light up or down.

/etc/acpi/events/backlight-up:


# called when brightness up key combo is pressed
event=ibm/hotkey HKEY 00000080 00001010
action=/etc/acpi/actions/backlight-up

/etc/acpi/events/backlight-down:


# called when brightness down key combo is pressed
event=ibm/hotkey HKEY 00000080 00001011
action=/etc/acpi/actions/backlight-down

Now we need some actions. I made a couple of simple bash scripts that looks at the current state of the back light level and subtracts or adds 1 to the level. You can control the level either in /sys/class/backlight/thinkpad_screen/brightness or in /proc/acpi/ibm/brightness the latter is as far as I know deprecated, so I am not going to use that.

So here are the scripts:

/etc/acpi/actions/backlight-down:


#! /bin/bash
# A little simple script to control backlight on a Thinkpad X60 Tablet

# Check current state
typeset -i state=`cat /sys/class/backlight/thinkpad_screen/brightness`
# Subtract one from the current state and echo it to the file
down=$((state-=1))
echo "$down" > /sys/class/backlight/thinkpad_screen/brightness

/etc/acpi/actions/backlight-up:


#! /bin/bash
# A little script to control backlight on a Thinkpad X60 Tablet

# Check current state
typeset -i state=`cat /sys/class/backlight/thinkpad_screen/brightness`
# Add one to the current state and echo it to the file
state+=1
echo "$state" > /sys/class/backlight/thinkpad_screen/brightness

Reload acpid and see if it works.


/etc/init.d/acpid restart

This should be it!

lsof -i; list information about Internet and network files

I talked to a person on IRC, who had a problem with his computer spamming his service provider with UDP packets. He solved his problem by using lsof -i, which lists information about Internet and network files.

Using more options for the -i parameter can give a more specific list of information.


                [46][protocol][@hostname|hostaddr][:service|port]

                where:
                     46 specifies the IP version, IPv4 or IPv6
                          that applies to the following address.
                          ’6’ may be be specified only if the UNIX
                          dialect supports IPv6.  If neither ’4’ nor
                          ’6’ is specified, the following address
                          applies to all IP versions.
                     protocol is a protocol name - TCP or UDP.
                     hostname is an Internet host name.  Unless a
                          specific IP version is specified, open
                          network files associated with host names
                          of all versions will be selected.
                     hostaddr is a numeric Internet IPv4 address in
                          dot form; or an IPv6 numeric address in
                          colon form, enclosed in brackets, if the
                          UNIX dialect supports IPv6.  When an IP
                          version is selected, only its numeric
                          addresses may be specified.
                     service is an /etc/services name - e.g., smtp -
                          or a list of them.
                     port is a port number, or a list of them.

Here is a sample:


tomasz@arcadia ~ $ lsof -i
COMMAND  PID   USER   FD   TYPE DEVICE SIZE NODE NAME
xchat   5362 tomasz   10u  IPv4  22056       TCP 192.168.1.107:54186->censored.dk:ircd (ESTABLISHED)
xchat   5362 tomasz   15u  IPv4  22063       TCP 192.168.1.107:47961->springtide.springtide.ca:ircd (ESTABLISHED)
xchat   5362 tomasz   20u  IPv4  22070       TCP 192.168.1.107:38401->underworld.rizon.no:6697 (ESTABLISHED)
xchat   5362 tomasz   25u  IPv4  22077       TCP 192.168.1.107:45011->efnet.pte.hu:9999 (ESTABLISHED)
xchat   5362 tomasz   30u  IPv4  22084       TCP 192.168.1.107:59340->jobe.wgops.com:ircd (ESTABLISHED)
pidgin  5372 tomasz   11u  IPv4  22337       TCP 192.168.1.107:60255->by1msg2175306.phx.gbl:1863 (ESTABLISHED)
pidgin  5372 tomasz   12u  IPv4  22298       TCP 192.168.1.107:45727->2605ds1-ynoe.1.fullrate.dk:xmpp-client (ESTABLISHED)
pidgin  5372 tomasz   16u  IPv4 168971       TCP 192.168.1.107:41941->by2msg2132817.phx.gbl:1863 (ESTABLISHED)
pidgin  5372 tomasz   17u  IPv4 168311       TCP 192.168.1.107:59297->by2msg1231704.phx.gbl:1863 (ESTABLISHED)

lsof can not only list information about Internet and network files, but list file information opened by processes and help solving problems in general. Just wanted you to know this cool application.