Tag Archives: bash-commands

automatic-shutdown-ubuntu

automatic shutdown in ubuntu

You shouldn’t waste a lot of system resources by keeping the computer in ‘on mode’ even though you aren’t using it ( Save Energy! ), should you? ( I hope your answer will be NO, ‘ for the sake of Humanity ‘ ). In some cases Auto shutdown command may help you a lot because it will automatically shutdown your computer at specific time (and of course you can use that command to shutdown your computer immediately from the terminal) and you can cancel the command in the mid time (I mean – before the scheduled time) if you want.

I often use this command, later I thought it might help you in saving a lot of valuable computing resources and energy. Since it is some kind of command – so if you think that ‘I may have to mess with Terminal or Linux shell’ then you need to relax! it’s one of the most simple command and you can learn it in few seconds. It doesn’t matter whether you are using Ubuntu 11.04 (Natty Narwhal) or 10.10 (Maverick Meerkat) or 10.04 (Lucid Lynx) or any other Linux based systems such as Linux Mint.

automatic-shutdown-ubuntu

Auto Shutdown Command in Ubuntu 11.04/10.10/10.04

Open Terminal(CTRL+ALT+T). To shutdown the computer at specific Time use (You may have to authenticate yourself by entering your ubuntu login password)  –

sudo shutdown -h HH:MM

e.g

sudo shudown -h 1:30

or if you want to shutdown now then just enter zero in place of time

sudo shutdown -h 0

The above method is used when you want to specify absolute time. On the other hand you can also specify relative value of time i.e 3 hours from now, using the following command –

sudo shutdown -h +3:00

That’s All..If you have any problem, then mention it in the comment.

bash commands tutorial

Learning some advance bash commands(Related to network) in bash isn’t a bad idea if you are going to troubleshoot networking problems or you are interested in other network hacks.Although you can do it in ubuntu 10.04(In some older versions too) by using a special tool named Network Tools which allows you to execute these commands in graphical mode.It can be found at system -> administrator -> Network Tools.But if you know some basic commands related to networking then it will be better.It is very simple and you can learn it within minutes.Here is the simple bash commands tutorial part 4…(If you don’t know about some simple bash commands then first read here..Bash commands for beginners )

Ping Command :

It is one of the most used commands in network testing and management.You need to know either ip address or host name of the target.The result of the ping command can be use to decide whether the target host is alive or not.The syntax of the command is ping, followed by its address(host name or IP address).
ping zzz.zzz.zzz.zzz  or ping www.yourtargetdomain.com
e.g
user@user-desktop:~$ ping www.yourtargetdomain.com
PING yourtargetdomain.com (hhh.hhh.hhh.hhh) 56(84) bytes of data.
64 bytes fr0m ubuntu.xyz.net (hhh.hhh.hhh.hhh): icmp_seq=1 ttl=49 time=287 ms
64 bytes fr0m ubuntu.xyz.net (hhh.hhh.hhh.hhh): icmp_seq=2 ttl=49 time=269 ms
64 bytes fr0m ubuntu.xyz.net (hhh.hhh.hhh.hhh): icmp_seq=3 ttl=49 time=272 ms
64 bytes fr0m hhh.hhh.hhh.hhh: icmp_seq=4 ttl=49 time=270 ms
64 bytes fr0m ubuntu.xyz.net (hhh.hhh.hhh.hhh): icmp_seq=5 ttl=49 time=287 ms
64 bytes fr0m ubuntu.xyz.net (hhh.hhh.hhh.hhh): icmp_seq=6 ttl=49 time=269 ms
64 bytes fr0m ubuntu.xyz.net (hhh.hhh.hhh.hhh): icmp_seq=7 ttl=49 time=269 ms
64 bytes fr0m ubuntu.xyz.net (hhh.hhh.hhh.hhh): icmp_seq=8 ttl=49 time=271 ms

Netstat Command :

Netstat is very useful in printing  the network connections,routing tables,network interfaces and multicast memberships.It has many advanced features that can be easily used by providing some options.Without any options it will display the list of open sockets.You can change the output by supplying options.

user@user-desktop:~$ netstat
unix  3      [ ]         STREAM     CONNECTED     9375     /home/user/.pulse/4f3877f89c59bcc05dbe2e5b4bb73a69-runtime/native
unix  3      [ ]         STREAM     CONNECTED     9374
unix  3      [ ]         STREAM     CONNECTED     9366     @/tmp/dbus-9GBsy9S5kY
unix  3      [ ]         STREAM     CONNECTED     9365
unix  3      [ ]         STREAM     CONNECTED     9322     /tmp/orbit-user/linc-5bc-0-6d4236a1652a7
unix  3      [ ]         STREAM     CONNECTED     9321
unix  3      [ ]         STREAM     CONNECTED     9320     /tmp/orbit-user/linc-602-0-19533f015c325
unix  3      [ ]         STREAM     CONNECTED     9316
unix  3      [ ]         STREAM     CONNECTED     9319     /tmp/orbit-user/linc-5fe-0-228e9d0f69c08

To display about kernel routing tables put -r , to know about the interfaces use -i and if you want the detailed statistics of each protocol then it is preferable to use -s.
e.g :
For Information about Interface :Using -i
user@user-desktop:~$ netstat -i
Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500 0    671613      0      0 0        671024      0      0      0 BMRU
lo        16436 0    103806      0      0 0        103806      0      0      0 LRU

For routing tables :
user@user-desktop:~$ netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.1.0     *               255.255.255.0   U         0 0          0 eth0
link-local      *               255.255.0.0     U         0 0          0 eth0
default         192.168.1.1     0.0.0.0         UG        0 0          0 eth0

Detailed statistics of protocol using -s
user@user-desktop:~$ netstat -s
Ip:
723094 total packets received
2 with invalid addresses
0 forwarded
0 incoming packets discarded
723053 incoming packets delivered
723066 requests sent out
Icmp:
367 ICMP messages received
2 input ICMP message failed.
ICMP input histogram:
destination unreachable: 353
source quenches: 14
69 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 69
IcmpMsg:
InType3: 353
InType4: 14
OutType3: 69
Tcp:
18586 active connections openings
6738 passive connection openings
3445 failed connection attempts
1310 connection resets received
13 connections established
711836 segments received
696851 segments send out
14235 segments retransmited
18 bad segments received.
7544 resets sent
Udp:
17343 packets received
69 packets to unknown port received.
0 packet receive errors
18471 packets sent

Options :
[-v] : To display some information about unconfigured address families.

[-n] : It will show the numerical address.

[-p] : To show the PID and name of the program to which each socket belongs.

[-l] : It will display only listening sockets.

[-c] : This will result in displaying the particular(selected) information every second continuously.

[-C] : Use to printing routing information fr0m its route cache.

Traceroute :

It is one of the most widely used commands,helpfull in tracing the route fr0m the a sender to a destination host.Actually it works by using TTL field of the IP protocol.For performing a trace the only required parameter is IP address or host name.There are many options available , some are desribed below.

Options :

[-I] : It uses ICMP(Internet control message access protocol) echos for probing.

[-T] : It uses TCP(Transmission control protocol) SYN for probes(Requires root power,so if you are not in root mode then start the command with sudo).

[-d] : It will enable the socket level debugging(If it is supported by your linux kernel).

[-F] : To prevent the fragmentation of the probe packets.

For Example : Tracing without any options
user@user-desktop:~$ traceroute www.yourtargetdomain.com
traceroute to www.yourtargetdomain.com (hhh.hhh.hhh.hhh), 30 hops max, 60 byte packets
1  192.168.1.1 (192.168.1.1)  1.204 ms  1.718 ms  2.220 ms
2  ABCD-XX-Static-rrr.rrr.rrr.rrr.wxybroadband.in (FFF.FFF.FFF.FFF)  19.496 ms  22.417 ms  25.827 ms
3  ABCD-XX-Static-rrr.rrr.rrr.rrr.wxybroadband.in (FFF.FFF.FFF.FFF)  21.537 ms  21.979 ms *
4  BBB.BBB.BBB.BBB (WWW.WWW.WWW.WWW)  29.870 ms  30.267 ms  33.412 ms
5  CFS-Static-NNN.NNN.NNN.NNN.mywxy.in (MMM.MMM.MMM.MMM)  260.056 ms  263.774 ms  266.282 ms
6  STWQLiteEthernet8-4.ar7.MNX1.dgyw.net (KKK.KKK.KKK.KKK)  265.844 ms  237.168 ms  424.466 ms
7  QQQ.QQQ.QQQ.QQQ (TTT.TTT.TTT.TTT)  267.514 ms  267.996 ms  268.273 ms
8  ek-dn2-core3-te9-1.rtr.ijkl.com (209.59.157.224)  274.020 ms  278.394 ms  280.310 ms
9  YYY.YYY.YYY.YYY (PPP.PPP.PPP.PPP)  281.858 ms  284.450 ms  285.917 ms
10  SSS.SSS.SSS.SSS (SSS.SSS.SSS.SSS)  290.453 ms  291.939 ms  298.095 ms
11  ubuntu.xyz.net (hhh.hhh.hhh.hhh)  301.548 ms  303.444 ms  303.724 ms

For more details on traceroute type : info traceroute in your bash shell.Actually you can learn bash commands fr0m the bash shell.Just type help command name or info command name or –help command name.

how to login as root in ubuntu 10.04

login as root

By default you can’t login as root in ubuntu 10.04 or other linux distribution due to the security policy of linux.Suppose you have logged in as root in ubuntu and by mistake you did something wrong then your system may be crash.But administrative power is required in some cases such as in installing some programs to solve file permission problem while working on file system.That’s why there is a simple solution and is sudo command.hence you can do administrative task or run administrative commands followed by sudo.Hence in this method you will have to work in command line interface.So in the case if you don’t know much more about ubuntu commands OR you feel irritating in doing some administrative task fr0m command line then you can enable the root login fr0m the login menu  and run as a root.

Hence It is very simple to enable root logging in graphical or GUI mode, just follow these simple steps –

step1. Open the bash terminal.

ubuntuuser@ubuntuuser-desktop:~$

step2. Type the command  sudo passwd root.First it will ask for the user password.Enter your current-user session password and and hit enter.

ubuntuuser@ubuntuuser-desktop:~$ sudo passwd root

[sudo] password for ubuntuuser:

step3. Then it will ask for new password.Enter a new password twice.This is the password you will use this in future for logging as root.

Enter new UNIX password:

Retype new UNIX password:

passwd: password updated successfully

ubuntuuser@ubuntuuser-desktop:~$

step4. To check whether it is working or not just logout fr0m the current session.At login prompt,choose other as a user account.Next, in the place of username write root and the password you just defined in the above step.

step5. that’s all..I hope your work is done.

NOTE : If you logged in as root then you must be careful about the each activities.After finishing the administrative task you should return to the normal mode.

You may like this post : A simple tutorial to learn- how to secure from internet threats.

What is sudo in Ubuntu?

Sudo commands in linuxIn early days it was difficult to manage the permissions for different users in a multiuser operating system that may be a client or server;suppose every user has a power of a superuser or root then any one of them may be misused the system either intentionally(If the user is smart) or ignorantly(If the user is a beginner one).Hence the simple solution of this problem is to limit the power for every users according to their need so that they can do simple tasks normally but in case of any administrative task root power is granted for small period(usually five minutes)by using the sudo commands.In sudo su stands for superuser and do means do(as usual).Hence sudo is mostly used by a permitted user for taking the permission to execute some commands as a another user or superuser, according to the information specified in sudoers file.Suppose the user that is invoking a command using the sudo power, is root then there is no need to enter user password.By default authentication is required and the user password is required; the user may use the sudo power again for short period of time(5-15min).So sudo is very useful in finishing some administrative task by a simple user.Now we are going to learn something more about the sudo commands.

Syntax of the sudo commands :


It is very simple..just use the word sudo before the actual command and hit enter.Then it will ask for the users password ..enter the password after the authorization process the commands will execute.e.g I am trying to execute commands1(installing a package using apt-get).

user840@user840-desktop:~$ sudo commands1
[sudo] password for user840:
Reading package lists… Done
Building dependency tree
Reading state information… Done

….and so on the execution will complete.

Options in SUDO :

-A : Using this option the another helper program(It may be in graphical format) is called and executed to read the password of the user and output the user password to the canonical output.

-u user : this option tells the sudo to run the target command as a user instead of root(which is default case).You may use UID rather than username by using UID followed by ‘#’.i.e #uid.
-a : It is used by the sudo to use the special authentication type for the validation of the user according to the permission settings stored in /etc/login.conf.
This option is is used only in the system having the support with BSD authentication mechanism.

-b : Specifying -b(background) with the sudo command simply means to order the sudo that “run the target command in background”.

-p prompt : By using -p (prompt) one can easily customize the password prompt.So using some ‘%’ escapes(e.g %H,%h,%p) you may use any other prompt rather then the default one.

Although there are many other options available but you can easily find out in your bash shell.just type info sudo and hit enter.

Environment Variables :

here are the some environment variables used by the sudo.

USER : Set to the current user.By default its value is equal to root if -u option is not specified.

SUDO_UID : user ID of the user who used the sudo.

SUDO_USER : Set to the login of the permitted user who is using sudo.
Go to your bash terminal for the details about the more environmental variables(info sudo OR man -k sudo OR help sudo).

Credit : Todd C. Miller

Learning Bash-Shell Commands-Tutorial-3

1. mv command : It is used for file from one directories to another.You have to first enter the file_name(that you want to move) and then
the new location of that file.
SYNTAX : mv filename new_location
rk10@rk-desktop:~/Desktop/log$ ls
passwd.txt
rk10@rk-desktop:~/Desktop/log$ cd ../
rk10@rk-desktop:~/Desktop$ cd test
rk10@rk-desktop:~/Desktop/test$ ls
login.txt  xyz.txt
rk10@rk-desktop:~/Desktop/test$ mv login.txt /home/rk10/Desktop/log
rk10@rk-desktop:~/Desktop/test$ cd ../log
rk10@rk-desktop:~/Desktop/log$ ls
login.txt  passwd.txt
rk10@rk-desktop:~/Desktop/log$

2. mkdir commmand : It is used for creating new directories.You have to just specify the name of the directory after mkdir,it will create a directory in the current working directory.
SYNTAX : mkdir : mkdir new_directory
rk10@rk-desktop:~/Desktop/log$ ls
login.txt  passwd.txt
rk10@rk-desktop:~/Desktop/log$ mkdir eagle
rk10@rk-desktop:~/Desktop/log$ ls
eagle login.txt  passwd.txt
rk10@rk-desktop:~/Desktop/log$

3. less command : Its works as a text reader because it can display text files contents.
SYNTAX : less file_name.txt
rk10@rk-desktop:~/Desktop/log$ less login.txt //press CTRL+Z to come back to command promopt.
this is the content of the file login.txt….
[1]+  Stopped                 less login.txt
rk10@rk-desktop:~/Desktop/log$

4. stat command : It is very usefull in veiwing file statistics,e.g creation date,modification date etc.stat command gives the complete status of the file.
SYNTAX : stat file_name
rk10@rk-desktop:~/Desktop/log$ stat login.txt
File: `login.txt’
Size: 37 Blocks: 8          IO Block: 4096   regular file
Device: 808h/2056d Inode: 1024062     Links: 1
Access: (0644/-rw-r–r–)  Uid: ( 1000/rk10)   Gid: ( 1000/rk10)
Access: 2010-03-14 19:31:46.000000000 +0530
Modify: 2010-03-14 19:31:25.000000000 +0530
Change: 2010-03-14 19:31:25.000000000 +0530
rk10@rk-desktop:~/Desktop/log$