Skip to main content

Posts

Showing posts with the label Tips and Tricks

Featured Post

Product Design of a 4 wheel differential drive robot

Display text in color - Linux terminal

Ever wanted to print text in colours? You can do it with ANSI escape characters. You can use ANSI codes in any programming language as long as the terminal supports it. echo -e "\e[31mRed" Red echo -e "\e[32mGreen" Green Replace the number to get different colors. You can make text bold, italics, underline etc. Following is a short table describing several codes. 39     Default 30     Black      31      Red    32      Green    33      Yellow     34      Blue     35      Magenta 36      Cyan    37      Light gray    97      White      For a complete reference, link . (The page has a complete list of ANSI codes)

Automating scripts using expect

Expect is one way to automate your scripts by expecting what the output may be. For example you want to create a script that helps you to login to a telnet session and enter your login and password for you. Here is the simple example which helps you to do it. Above example will login to your router and enter your username and password and list all the possible commands using ? and then let you to interact with using interact command. You can automate anything for example applications, ssh etc..

Linux command awk extract anything

Awk is pretty use full when you are writing automatic scripts to do your jobs. Some simple examples of how we can use awk are given below ps | awk '{print $1}' It will print first column of ps command.  If you want to print second column also write ps | awk '{print $1 $2}' Output seems to be pretty crowded? Add a simple space by ps | awk '{print $1 " " $2}' Want to limit it display only second line? ps | awk ' NR==2{print $1 " " $2}' Want to exclede first row? You can do it by ps |awk 'NR !=1{print  $1 " " $2}' Similarly you can print rows greater than a value by ps |awk 'NR >1{print  $1 " " $2}' You can extract virtually anything using awk... Feel free to explore every options. Type man awk or awk --help to explore other options. Feel free to comment also... :) This site has some good examlpes.

Pass output of one command to argument of other

Well Linux is famous for combining things in power full ways in which anything is possible from a command line. The real fun of Linux came when you start focusing on terminal to do everything... It's possible to pipeline commands in terminal. Also it's possible to pass output of something as an argument of other. For example you can ping to your own external ip by ping $(curl -s  curlmyip.com) curl curlmyip.com returns you ip address. This address is passed to  the telnet as an argument. Whatever you put between $( and ) will execute as if it is a bash command.

How to know external IP address from Linux terminal?

ifconfig displays only local ip address of your system. If your system is directly connected to internet then it will be your external ip address. It may not be the case always. Because you will be behind a router or a modem. You can know the external IP address by going to www.whatismyip.com or www.ipecho.net . If you want to know it from a terminal type curl curlmyip.com What curl do is it fetches the content of the link to the terminal. There are also several other websites that offers this same service. Some of them are listed below. curl  ipecho.net/plain curl myexternalip.com/raw curl curlmyip.com curl ifconfig.me/ip curl icanhazip.com curl ip.appspot.com

How to set dns address in android phones?

Ever wondered how setup dns address in android phones. You can do it if your phone is rooted. You may have a terminal installed with busybox if your phone is rooted. Otherwise install a terminal and gain root permission by typing su Then list all the device dns entries using this command getprop | grep dns Then set the dns entries by the command setprop net.rmnet0.dns1  8.8.8.8 Here rmnet0.dns1 is given as an example. This may vary depending on which dns entry you have to choose. 8.8.8.8 is the googles dns server address. Replace it with your choice.

How to send AT commands?

For details about AT commands refer this link . If you are using windows you can use hyperterminal to communicate with any modem. In this case the GSM modem. Find a method to connect your GSM modem to the PC  (Refer this Link  ). You can use a USB2TTL converter to directly interface your GSM modem to PC. After interfacing the modem go to device manager and find the com port no: assigned to your GSM modem. After identifying the port number open hyperterminal. You need to download Hyperterminal or copy the files from windows XP. You can also use putty for this purpose.  Type a name and click OK. Then select the com port you are using and press ok. Change the boadrate to 9600(you can choose other also. Higher boadrates may not work with some GSM modem) and let other options remain unchanged. After that type AT and press Enter. If you get a response showing OK. Then everything is fine. As a default typed character are not shown in the terminal. You can enab...

How to hide and unhide files in Linux?

If you are new to linux OS, it's a common mistake to add a (.) in front of your files and suddenly the file disappears. In Linux filenames starting with a dot (.) are hidden. You can intentionally make a folder or file hidden by renaming it. mv filename .filename If you want to view you hidden files or folders, first go to the location where the file resides using cd command. cd /root/Desktop/ Then list all files and folders using ls command. ls -a If you want to permanently unhide then use mv command again. mv .filename filename

Creative Destruction | Batch Hacks

Ever tried to put windows to crawl? Let’s do it. This simple code is an infinite loop where each time it runs a copy of itself. The amount of computational power it requires increase exponentially. With an i5 configuration with descent RAM your PC will hang in seconds. You won’t even get time to kill the process or log off. One thing you can do is to shut you PC using your power button.  You will have 5 second timer. It will execute only after 5 seconds. It won't do any harm to your PC other than hanging… Use it for educational purpose only… Save this file as tryme.bat and run it.

Mark all Gmail messages as read

  I have huge collection of unread e-mails.. I usually won't open unwanted or junk e-mails. And of course over a period of time, I have about 1000 unread messages right in my mailbox. It’s very annoying to go through all 20 results(listed in a page) and marking all as read. Every time I got a new mail it shows, hey you have 1001 unread e-mails. So I found a solution to mark all the unread e-mails as read in a single step. Go to your Gmail inbox and search the key word is:unread When you got the search result select the option Mark All. Then there is an option to mark all the search result. Click it and then Mark all as read.