Pages

Showing posts with label shellscript. Show all posts
Showing posts with label shellscript. Show all posts

Tuesday, August 24, 2010

பாடம் 1: shell script தொடர்.....

shell script என்றால் என்ன:-

லினக்சின் கட்டளை வரிகளை shell என்று அழைக்கிறோம்.இந்த shell களில் linux -ஐ இயங்க செய்ய அனைத்து அம்சங்களை கொண்டுள்ளது.இது மற்ற நிரல்களை போல வாக்கிய அமைப்புக் கொண்டுள்ளது எனவே shell script ஆனது கட்டளைகளை பயன்படுத்தி உருவாக்கப்பட்டு பின்னர் செயல்படுத்தப்படுகின்றது.

shell script என்ன செய்கின்றது:-

* user மற்றும் file லிருந்து input னை பெற்று output னை display செய்கின்றது.
* தங்களுக்கு தேவையான command னை உருவாக்கலாம்
* Automatic ஆக ஒரு வேலையை செய்ய செய்யலாம்
* நம்முடைய வேலை நேரத்தை குறைக்க முடியும்.
* system admin வேலையைக்கூட automatic ஆக்கலாம்.

shell -ன் வகை மற்றும் அதன் location :-

* Bourne shell (sh)-/bin /sh
* c shell (csh)-/bin /csh
* Korn shell (ksh)-/bin /ksh
* Bourne again shell (bash)-/bin /bash
* csh compatible shell (tch)-/bin /tcsh
* Restricted shell (rsh)-/usr /bin /rsh

எப்படி shell script -னை எழுதுவது?

* vi editor னை ஓபன் செய்து script னை எழுதலாம்.

எ.க:-

$ vi first
#
# My first shell script
#
clear
echo "Knowledge is Power"

* script னை எழுதிய பிறகு தங்களுடைய script file ன் permission னை மற்ற வேண்டும்.

எ.க:-

$ chmod 755 first
$ ./first

syntax :-

bash your-script-name
sh your-script-name
./your-script-name

எ.க:-

$ bash bar
$ sh bar
$ ./bar

ஒரு எளிய உதாரணம் :-

* terminal னை ஓபன் செய்து vi ginfo என்று type செய்க பின்னர் இந்த code னை paste செய்க.

#
#
# Script to print user information who currently login , current date & time
#clear
echo "Hello $USER"
echo "Today is \c ";date
echo "Number of user login : \c" ; who | wc -l
echo "Calendar"
cal
exit ௦

* பின்னர் esc மற்றும் : + wq key யை அழுத்தி இந்த ginfo script னை save செய்க.

* terminal ல் $sh ginfo என்று type செய்க இப்படி ஒரு output தோன்றும்.
இந்த script system ல் உள்ள தேதி,user மற்றும் காலேண்டர் னை terminal ல் காண்பிக்கும்.

விளக்கம்:-

* # -என்பது comment line

* echo - இது நாம் " " குள் தரும் எதையும் print செய்யும்

* who ,date ,cal ,$user -என்பது நாம் அறிந்த command