Posts

Showing posts with the label bash

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!

Check which route for specific domain in Linux

Image
Working from home during pandemic, requires most of us to connect to office network through VPN. Some of us are getting used to having multiple VPNs to multiple site offices. When connected to VPN, most of the time that this VPN connection routed all of our traffic through their VPN connection which is not what we want because our home internet is much faster and is not restricted to certain office policies.

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...

Howto Backup and Restore SD card image with tar and dd

Image
Just my quick post today... I'm quite busy these days... I normally backup my embedded system SD card image using dd and the output size will be 969M. To reduce the size, I'm using tar and gzip to compress the image file. Here is the command: # dd if=/dev/sdd of=sd1gb.dd $ tar zcvf sd1gb.dd.tar.gz This way I will have the image in tar.gz file which is only 218MB. And delete the dd file. However, to use the tar.gz, we don't have to extract the file because we can only use a single command like this: # tar Ozxf sd1gb.dd.tar.gz | dd of=/dev/sdd That's all for today... see u later!

Some Photos from my office's Desktop

Image
It is Sunday, and I'm checking my old photos... And then, I found my office's desktop photos. You may want to see them. Sometimes, my desk is clean but sometimes, it get horribly messy... This is the average looks of it. Working on these Wireless Rain Gauge development have build up my skills in linux bash programming and I learn a lot on how Single Board computer works. In the beginning, we just create a daughter board and attach it to a hacked LinkSYS WRT45GS board which I've installed OpenWRT so I can embed my bash script inside. But then, we go for TS-7260 board from embeddedarm.com to get more control on the RainGause for version two. Till now, I'm still upgrading the code for more features and stability. Well, that's all for now. Enjoy what you're doing!!

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...

DNS Domain Expiration Checker Script [Update for .my domain]

Image
Do you have more than one domain to manage? Have you ever failed to renew your domain before it expires? This simple domain-check script maybe your life saver. Originally, it was written by Ryan Matteson . Then Vivek Gite add up support to .org, .in, .biz and .info domain names. And now, I've updated the domain-check script to support Malaysia (.my) domain. I should call this DNS Domain Expiration Checker Version 1.6 In order to use the script, you can simply download the script and rename it to domain-check . Then chmod +x to be able to execute it. You can run it to parse a list of domain in a text file and send an email alert to you for any domain that about to expire. Command line code to download: $ wget http://coderstalk.googlepages.com/domain-check.txt -O domain-check Sample Usage: (in directory where you place the script) apogee@apogee-persiasys:~$ ./domain-check -d google.com.my Domain Registrar Status Expires Days Left -------...