Warn when battery is low

2020-08-30 2 min read Learning Bash Scripting

I am very lazy to look at battery status and want to be warned when the battery is low. This means that even if I am away from the laptop, I can be warned that laptop is about to poweroff due to battery low. So, what kind of alerts I can have, many -

  1. zenity message box
  2. email
  3. sms with twillio
  4. Telegram message and possibility is endless.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22

LOW=35 ## This si the lowest percentage at which I want the alerts.
## Parse the acpi statue and decide if alert needs to be sent
per=$(/usr/bin/acpi -b | awk '{print $4}'|sed 's/%.*//') 

# source ~/bin/cron-scripts/sendsms.sh
if [[ $(/usr/bin/acpi |grep -c "Full\|Charging") > 0 ]]
then
    #This is when the AC is connected.
    exit 0
fi


if [[ ! -z $per && $per < $LOW ]]
then
    # sendsms "Battery is at $per%"
    export sub="Battery is at $per%"
    echo "Battery is running out : $per"|/usr/sbin/sendmail -t
    display_msg.sh "ACPI Warn" "Battery is at $per%"
    echo "ACPI Warn" "Battery is at $per%" | /home/amitag/bin/twilio-sms +919535210501
    zenity --warning --text="Battery is at $per%"
fi

Put this script somewhere and schedule in cron for every minute and enjoy.

Continue reading

Some good find alias.

2020-08-23 1 min read Learning Bash

Here are some interesting alias’s that you may want to add to your bashrc file or where-ever else you add your aliase’s. Very useful if you use find commonly.

There are four aliases defined here and have a comment explaining what it does. but these are so simple and useful that you probably dont even need the comments.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

# ff:  to find a file under the current directory
ff () { find . -name "$@" ; }
# ffs: to find a file whose name starts with a given string
ffs () { find . -name "$@"'*' ; }
# ffe: to find a file whose name ends with a given string
ffe () { find . -name '*'"$@" ; }
# very very useful function: for finding files with ignore case, just type "f <part of filename>"
# This in combination with alias for 'g' is deadly.
#
f () { find . -iname '*'"$@"'*' ; }

Hope this is useful for you.

Continue reading

The power of find command in Linux – advanced.

2010-05-24 2 min read Linux

Generally whoever uses Linux, would know about the find command. Find the man page <a href="http://amit.themafia.info/phpMan.php?parameter=find&mode=man" target="_blank">here.

There are also lots of blogs, tutorials and other articles on find command on the web, so why write another one. Because it&#8217;s worth every word spent on it πŸ™‚
find is a very powerful command, let&#8217;s see how (options for find command from man page and usage):

–depth β€” Process each directory&#8217;s contents before the directory itself.
–maxdepth β€” Descend at most <span style="text-decoration: underline;">levels (a non-negative integer) levels of directories below the command line arguments.
–xdev β€” Don&#8217;t descend directories on other filesystems.
–executable β€” Matches files which are executable and directories which are searchable (in a file name resolution sense).
This takes into account access control lists and other permissions artefacts which the -perm test ignores.
–iname β€” Like -name, but the match is case insensitive.
–nogroup β€” No group corresponds to file&#8217;s numeric group ID.
–nouser β€” No user corresponds to file&#8217;s numeric user ID.
–fls <span style="text-decoration: underline;">file β€” True; like -ls but write to <span style="text-decoration: underline;">file like -fprint.
–ok <span style="text-decoration: underline;">command β€” Like -exec but ask the user first (on the standard input);
–print0 β€” True; print the full file name on the standard output, followed by a null character
(instead of the newline character that -print uses).
–printf <span style="text-decoration: underline;">format β€” True; print <span style="text-decoration: underline;">format on the standard output, interpreting &#8217;&#8217; escapes and &#8217;%&#8217; directives.

Continue reading

Tip: Using find Command in Linux

2009-12-10 2 min read Linux

Ok this I was planning for quite sometime.. but found this <a href="http://www.pinoytux.com/linux/tip-using-find-command-in-linux" target="_blank">here. Worth reading for people who want to start off using find command.

Doing command-line stuff in Linux is fun. It may be intimidating for some at first, now that we are in the age where GUI is no longer an option. But with CLI, we can do so many things that can be accomplished faster if we know how to utilize the features of a certain command.

Continue reading