Blog Archive
-
▼
2009
(8)
-
▼
October
(8)
- Sending mails using the command line
- Let us ping range of IPs machine
- Useradd via shell script IN Linux
- To check desire machine status for up or down by I...
- To know Disk space Alert by mail in Linux
- Access Windows shares from the terminal
- Aircel/Airtel GPRS on linux via USB cable/bluetoot...
- To check Linux service is on or off
-
▼
October
(8)
Saturday, October 24, 2009
Sending mails using the command line
#/etc/init.d/sendmail status
if the status shows that it;s not, then start it;
#/etc/init.d/sendmail restart
then , send mails using either the mail or mutt command;
#ehco "body of the mail" | ,ail -s "Subject of the mail" toAddress
Give the recipient's mail ID in place of toAddress.
As for the body of the mail, you can also redirect it from a file, as follows,
#mail -s "subject of the mail" toAddress < body_mail.txt
If u want to send a file as an attachment, you can use mutt instead:
#echo "body of the mail" | mutt -s "subecjt of the mail" \-a fileToAttach.txt toAddress
Give the recipient's email ID in place of toAddress.
Let us ping range of IPs machine
#!/bin/bash
#Author:- Deepak G Ghule
#Date :- 25/10/2009
#Subject :- Let us ping range of IPs to know the status of machine (UP/DOWN)
for i 192.168.1.{1..255}; //checks 192.168.1.x class of IPs
do
ping -c2 $i > /dev/null;
[ $? -eq 0 ] && echo $i is up
trap "exit" SIGINT //To force exit when Ctrl+c keystroke is applied
done
now save it as net.sh
now give the execute persmission with following command
[crackmind@crakmind.com~]#chmod +x /netsh.sh
thanks for visit my blogs
Monday, October 19, 2009
Useradd via shell script IN Linux
#if [ $(id -u) -eq 0 ]; then
echo "Enter username"
read user
echo "User password"
read pass
egrep "$user" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$user exist"
exit 1
else
pass1=$(perl -e 'print crypt($ARGV[0], "pass")' $pass)
useradd -m -p $pass1 $user
echo "User has added successfully" || echo "failed to add username"
fi
To check desire machine status for up or down by IP address using ping test
#Author- Deepak G Ghule
#Subject- To check desire ip address
echo "Plz enter Your desire IP address to ping test"
read ip
ping -c 4 $ip &>/dev/null
if [ $? -eq 0 ]; then
echo "Machine is up now"
else
echo "Machine is down"
fi
To know Disk space Alert by mail in Linux
#Subject:- To know Disk space alert by mail
#Author- Deepak G Ghule
echo "Please put the partition to check"
read partition
var=`echo "$(df -k $partition | awk 'NR > 1 { print $5 }' | cut -d "%" -f1)"`
if [ $var -lt 75 ] && [ $var -lt 80 ]; then
echo "System is working with $var"
echo $var > mail -s "Disk space is use"
elif [ $var -lt 85 ]; then
echo $var > mail -s "Disk space is use" root
echo "system is in warning with $var:"
elif [ $var -gt 85 ]; then
echo $var > mail -s "Disk space is use" root
echo "System in dangerous zone"
fi
Wednesday, October 14, 2009
Access Windows shares from the terminal
#kdir /mnt/win
#mount -t cifs //server-ip-or-machine name/share/mnt/win -o username=user.password=pass.domain=DOMAINNAME
And to unmount the share.use the command give below:
#umount /mnt/win
Aircel/Airtel GPRS on linux via USB cable/bluetooth using KPPP GUI tool
Steps for USB cable using KPPP configuration
1) connect ur nokia mobile to system
2)Check ur nokia connection as it's vendor and product number
[root@server1 ~]# lsusb
Bus 001 Device 001: ID 0000:0000
Bus 002 Device 004: ID 0421:0061 Nokia Mobile Phones
Bus 002 Device 003: ID 0e0f:0002
Bus 002 Device 001: ID 0000:0000
3)Add ur modem here with following command
[root@server1 ~]# sudo /sbin/modprobe usbserial vendor=0x421 product=0x061
4)add ur setting with following command
[root@server1 ~]# wvdialconf /etc/wvdial.conf
Scanning your serial ports for a modem.
ttyS0<*1>: ATQ0 V1 E1 -- failed with 2400 baud, next try: 9600 baud
ttyS0<*1>: ATQ0 V1 E1 -- failed with 9600 baud, next try: 115200 baud
ttyS0<*1>: ATQ0 V1 E1 -- and failed too at 115200, giving up.
ttyS1<*1>: ATQ0 V1 E1 -- failed with 2400 baud, next try: 9600 baud
ttyS1<*1>: ATQ0 V1 E1 -- failed with 9600 baud, next try: 115200 baud
ttyS1<*1>: ATQ0 V1 E1 -- and failed too at 115200, giving up.
Port Scan<*1>: S2 S3
WvModem<*1>: Cannot get information for serial port.
ttyACM0<*1>: ATQ0 V1 E1 -- OK
ttyACM0<*1>: ATQ0 V1 E1 Z -- OK
ttyACM0<*1>: ATQ0 V1 E1 S0=0 -- OK
ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK
ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK
ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
ttyACM0<*1>: Modem Identifier: ATI -- Nokia
ttyACM0<*1>: Speed 4800: AT -- OK
ttyACM0<*1>: Speed 9600: AT -- OK
ttyACM0<*1>: Speed 19200: AT -- OK
ttyACM0<*1>: Speed 38400: AT -- OK
ttyACM0<*1>: Speed 57600: AT -- OK
ttyACM0<*1>: Speed 115200: AT -- OK
ttyACM0<*1>: Speed 230400: AT -- OK
ttyACM0<*1>: Speed 460800: AT -- OK
ttyACM0<*1>: Max speed is 460800; that should be safe.
ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
WvModem<*1>: Cannot get information for serial port.
ttyUSB0<*1>: ATQ0 V1 E1 -- failed with 2400 baud, next try: 9600 baud
ttyUSB0<*1>: ATQ0 V1 E1 -- failed with 9600 baud, next try: 115200 baud
ttyUSB0<*1>: ATQ0 V1 E1 -- and failed too at 115200, giving up.
Found an USB modem on /dev/ttyACM0.
Modem configuration written to /etc/wvdial.conf.
ttyACM0
[root@server1 ~]#
[root@server1 ~]# vim /etc/wvdial.conf
[root@server1 ~]# wvdial
--> WvDial: Internet dialer version 1.54.0
--> Cannot get information for serial port.
--> Initializing modem.
--> Sending: AT+CGDCONT=1,"IP","aircelgprs","",0,0
AT+CGDCONT=1,"IP","aircelgprs","",0,0
OK
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
OK
--> Modem initialized.
--> Sending: ATDT*99#
--> Waiting for carrier.
ATDT*99#
CONNECT
~[7f]}#@!}!} } }2}#}$@#}!}$}%\}"}&} }*} } g}%~
--> Carrier detected. Starting PPP immediately.
--> Starting pppd at Sun Oct 4 03:25:12 2009
--> pid of pppd: 9507
--> Using interface ppp0
--> pppd: 60800
--> pppd: 60800
--> pppd: 60800
--> pppd: 60800
--> local IP address 10.183.117.164
--> pppd: 60800
--> remote IP address 10.6.6.6
--> pppd: 60800
--> primary DNS address 202.148.200.3
--> pppd: 60800
--> secondary DNS address 202.148.202.4
--> pppd: 60800
Caught signal #2! Attempting to exit gracefully...
--> Terminating on signal 15
--> pppd: 60800
--> Connect time 7.2 minutes.
--> pppd: 60800
--> pppd: 60800
--> pppd: 60800
--> Disconnecting at Sun Oct 4 03:32:23 2009
root@server1 proc]# cat /etc/wvdial.conf
[Dialer Defaults]
Modem = /dev/ttyACM0
Init1 = AT+CGDCONT=1,"IP","aircelgprs","",0,0
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Baud = 460800
#Init1 = ATZ
#Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ISDN = 0
Modem Type = USB Modem
; Phone =
; Username =
; Password =
Username = a
Password = a
Phone = *99#
Stupid Mode = 1
check the kppp pakage and start ur linux in graphic mode with startx
open kppp-->applications-->internet-->kppp
click on configure-->click account tab and click on new-->Manual setup-->dial-->connection name--aircel
clikc add--enter a phone no as put-->*99#--ok-->0k
click on Modems tab-->>New-->Modem name--/dev/ttyAMC0-->modem device-->select /dev/ttyAMC0
now click on Modem tab-->Modem commands-->
Initialization strings1=AT+CGDCONT=1,"IP","aircelgprs","",0,0
Initialization strings2=ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
click -ok
Query Modem to test it-
click ok and ok
put the user name=a
password = a
now connect ur aircel gprs properly
HOWTO: Airtel GPRS on Linux via Bluetooth
Here’s a mini HOWTO explaining how Airtel GPRS users can connect their linux boxes to the net using only a bluetooth connection from their phone. That’s right, no data cable required!
NOTE: I’ve only tried this on Debian but it should work fine on just about any distro.. use your distro’s package management tool instead of apt.
Follow these steps:
1. First make sure GPRS (Mobile Office) is enabled on your phone. This won’t work with Airtel Live :P
2. Install the Bluetooth utilities:
sudo apt-get install bluez-gnome bluez-utils
3. Find the MAC address of your phone:
hcitool scan
The output should be something like this:
Scanning ...
00:19:63:74:XX:YY saurav
Write down this address somewhere for future reference.
4. Now, determine the channel used for dial up networking using the MAC you just found:
sdptool browse 00:19:63:74:XX:YY
...
Service Name: Dial-up Networking
Service RecHandle: 0x10001
Service Class ID List:
"Dialup Networking" (0x1103)
"Generic Networking" (0x1201)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 1
Profile Descriptor List:
"Dialup Networking" (0x1103)
Version: 0x0100
In this case, the required channel is channel no. 1. This will be used to configure the bluetooth connection.
5. Open up /etc/bluetooth/rfcomm.conf with your favorite editor.
sudo nano -w /etc/bluetooth/rfcomm.conf
Make it look something like this (replace with your MAC address and channel):
rfcomm0 {
bind yes;
device 00:19:63:74:XX:YY;
channel 1;
comment "Dial-up Networking";
}
6. Next, restart bluetooth services:
sudo /etc/init.d/bluetooth restart
7. We’re done with the bluetooth configuration. Now we need to configure wvdial:
8. Install wvdial
sudo apt-get install wvdial
9. Run wvdialconf. This generates a dummy /etc/wvdial.conf
sudo wvdialconf
10. Now we need to edit /etc/wvdial.conf and feed in the values for the GPRS connection:
sudo nano -w /etc/wvdial.conf
It should look something like this:
[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
stupid mode = 1
Modem Type = Bluetooth Modem
Baud = 115200
New PPPD = yes
Modem = /dev/rfcomm0
ISDN = 0
Phone = *99#
Username = a
Password = b
11. We’re done. Make sure Bluetooth is turned on in your phone and enter the following command to connect:
sudo wvdial
It might ask you for a PIN the first time you connect, in which case you must enter the same digits in the phone and PC in order to pair them.
12. Press Ctrl-C when you want to disconnect.
To check Linux service is on or off
# Subject:- To check service is on or off.
#Developed by DEEPAK G GHULE
#Date 13/10/2009
date
echo "Plz Enter service name for service status:"
read service
ps -C $service &>/dev/null
if [ $? -eq 0 ]; then
echo "$service is running"
else
echo "$service is not running"
fi
PS3="Please select the option to restart the $service Yes[1]/No[2]:"
LIST="Yes No"
select i in $LIST
do
if [ $i = "Yes" ]; then
chkconfig --level 35 $service on
/etc/init.d/$service restart &>/dev/null
echo $service is running now
elif [ $i = "No" ]; then
chkconfig --list | grep $service
fi
break
done