Posts

Showing posts with the label Linux shell script

Bash Tricks Of The Day: Brace Expansion

Image
Welcome, Linux enthusiasts, to another exciting episode of "Bash Tricks Of The Day"! Today, we'll explore a powerful and time-saving feature of bash known as Brace Expansion. Brace yourself for this mind-bending trick that will level up your command line wizardry!

Bash Scripting - How to Concatenate Strings

Image
Somewhere around 1989, Brian Fox created Bash as a free software substitute for the Bourne shell for the GNU Project . It is a command processor, usually running in a text window, where the user can write commands that cause actions. Bash can also read and execute commands from shell script files . It supports filename globbing (wildcard matching), piping, here documents, command substitution, variables, and control structures for conditional testing and iteration, as do other Unix shells.

How to install notify-send in ubuntu

Image
notify-send is a command to send desktop notifications to a notification daemon. It is included in libnotify-bin package, which is a library that sends desktop notifications to a notification daemon, as defined in the Desktop Notifications spec. These notifications can be used to inform the user about an event or display some form of information without getting in the user's way.

Custom Gnome Notification for your apps

Image
When you run a command that would take long time to finish, you would rather do something else beside staring at the terminal to wait until it finished to do the next procedure. In my case, if I write the SD cards for my ts-7260, I would leave it and do other stuff. Since it is easy to get distracted with so many stuff on the internet, I sometimes forget to get back to check the dd terminal. This could waste my time because the process have stopped for quite long time where I should write another card instead just right after the first card finished. Therefore, I use notify-send from libnotify-bin package to notify me about my process while I'm free to check my mail, reading, surfing and so on. Here is the screenshot of my gnome notification when it is ready. It can be done with one line of command like this: notify-send -i /usr/share/icons/Human/scalable/devices/media-flash.svg \ -h int:x:$(xrandr -q|grep '*' | sed -e 's/x.*//' -e 's/\ //g') \ -h int:y...

Bash Scripting - Script execution counter

This Linux shell script does nothing than just increasing n value every time it is executed and then keep the value in a file. When the value goes greater than 10, it will drop back to 1. Uhhh... this reminds me to the increasing of the fuel price. But that fuel price will just increase and will never drop back... Lol... Anyway, I wrote this bash script just to make a permanent variable to be used as bash script running counter. With this code, I can count how many time the script have been executed. Here's the code: #!/bin/sh nfilename="./nvalue" n=0 touch $nfilename . $nfilename echo "current n value is $n" n=$(expr $n + 1) if [ $n -gt 10 ]; then n=1 fi echo "new n value is $n" echo "n=$n" > $nfilename Here's the step for testing the script for newbies bash scripter. 1. Create one text file in your home folder. In this example I'm using ncounter as the file name: apogee@apogee-persiasys:~ gedit ncounter 2. Copy and p...

Linux Shell Script to Compare PID

Image
Just my testing Linux bash script code to compare PID... I'm not really using it yet. But I'm thinking if I can use it to verify that there is running process with the same PID in /var/run/appname.pid on the running process snapshot (ps). if there is no such PID, maybe I can simply delete the .pid file. And the process which will check for this file can restart as usual. Here's the content of my ~/pidcmp script: #!/bin/sh thepid=`cat /var/run/ppp0.pid` echo "the pid is $thepid" spsaux=`ps aux | grep [p]ppd` okflag=0 gettx () { local IFS=" " i=0 for tx in $1; do myarr[$i]=$tx let i+=1 done } NEWLINE=' '; oldifs=$IFS IFS=$NEWLINE for line in $spsaux; do # echo "line: $line" gettx $line foundpid=${myarr[1]} if [ $foundpid == $thepid ]; then echo "the pid is equal!!" okflag=1 fi done #echo "foundpid: ${myarr[1]}" IFS=$oldifs echo "okflag = $okflag" This is ju...