Upload
dkin1234
View
229
Download
0
Embed Size (px)
Citation preview
8/10/2019 All Unix Practical Programs
1/23
UNIX Shell Script
Subject Name: Programming Skills-V (OS)Subject Code: 630007
(2a) Accept numbers and perform addition, subtraction, diision andmultiplication
echo !enter the alues a ::!read aecho !enter the alues of b:!read becho !"#$ %A&U$ ' A::! aecho !"#$ %A&U$ ' *::! b
echo !A++I"I'N ' :: e-pr a . b !echo !SU*"/$C"I'N ::! e-pr a 01 b echo !U&"I3&ICA"I'N::! e-pr a 04 b echo !+I%ISI'N ' ::! echo a 5 b 6bc 1l echo !'+UA& ::! echo a 7 b 6bc
(2b) Accept the strin8 and chec9s hether the strin8 is palindrome or not;
echo !$nter a Strin8!
read strlen
8/10/2019 All Unix Practical Programs
2/23
UNIX Shell Script
(2c) Accept number and chec9 the number is een or odd, Bnds the len8th ofthe number, sum of the di8its in the number;
echo !Dien number is een or odd!echo !$nter a Number!read nocleartemp temp 1eE ? @then
echo no! is een!else
echo no !is 'dd!
Blen
8/10/2019 All Unix Practical Programs
3/23
UNIX Shell Script
echo !After /eplacin8: ! str
(2e) Accept Blename and displas last modiBcation time if Ble e-ists,otherise displa appropriate messa8e;
echo !$nter ile Name!read fnmaeif > 1f fname @then
echo !ile $-ist!Gecho ls 1l 1t 68rep fname 6cut 1fH 1d
else
echo !ile does not e-ist;;!BGls 1l 1t 68rep J;sh 6cut 1fH 1d Gls 1l 1t 68rep J;sh 6cut 1fH 1d
(2f) etch the data from a Ble and displa data into another Ble in reerseorder
echo !etch data from another Ble!ls 1aecho !$nter ile Name!read fNamere fName K tempcat temp
(L) Mrite a script to Bnd the 8lobal complete path for an Ble;
echo !+ispla Dlobal path for a Ble!echo !$nter Ble name!read fNameecho fNameecho pd
L *IC1Chaparda >;8tu1mca;blo8spot;com@ 3repared *: *har8a /aja8or
8/10/2019 All Unix Practical Programs
4/23
UNIX Shell Script
() Mrite a script to broadcast a messa8e to a speciBed user or a 8roup ofusers lo88ed on an terminal
echo !$nter user Name!
read uName
user user 18t ? @
then
echo user
rite uName
else
echo !0n*rodcast messa8e to all lo88in users!
echo !0n$nter our messa8e!
echo !0n>$nter ctrl . d to stop@!
all
B
(O) Mrite a script to cop the Ble sstem from to directories to a ne
director in such a a that onl the latest Ble is copied in case there arecommon Bles in both the directories;
echo !Cop all Bles from one director to another director!echo !$nter ull path forSource +irector!read s+irecho !$nter ull path for "ar8et +irector!read t+ircp 1/u s+ir t+irGe;8 for current director ou place ;;5PdirNameK
*IC1Chaparda >;8tu1mca;blo8spot;com@ 3repared *: *har8a /aja8or
8/10/2019 All Unix Practical Programs
5/23
UNIX Shell Script
Gif ou ant to cop in current director then ;;5Pne +irector NameK
(Q) rite a script to compare identicall named Bles in to diRerentdirectories and if the are same, cop one of them in a third director;
echo !/ead Bles from Brst +irector!
read s+ir
echo !/ead Bles from second +irector!
read t+ir
ls 1d
echo s+ir
cd ;;5s+ir
ls 1l
Bles
8/10/2019 All Unix Practical Programs
6/23
UNIX Shell Script
Bnd ; 1perm 5u
8/10/2019 All Unix Practical Programs
7/23
UNIX Shell Script
hich (of UNIX)
(=L) Mrite a script for 8eneratin8 a mar9 sheet after readin8 data from a Ble;ile contains student roll no, name , mar9s of three subjects;
echo !/ead data from Studentar9Sheet Ble!echo !Student /ollNo!
echo cat Studentar9sheet 6cut 1f =echo !$nter Students /oll No :!read rNolNo
8/10/2019 All Unix Practical Programs
8/23
UNIX Shell Script
(ile Studentar9sheet[s detail li9e := /am O J JH)
(=) Mrite a script to ma9e folloin8 Ble and director mana8ementoperations menu based:
+ispla current director&ist director
a9e directorChan8e directorCop a Ble/ename a Ble+elete a Ble$dit Ble
echo ! =:+ispla current +irector!echo ! 2:&ist +irector!echo ! L:a9e director !
echo ! :Chan8e director !echo ! O:Cop a Ble !echo ! Q:/ename a fIle !echo ! J:+elete a Ble !echo ! H:$dit a Ble !echo ! $nter Four Choice: !read chcase ch in =) pd
WW 2) ls 1d WW L) echo $nter director name to ma9eread dir\name m9dir dir\name WW )
H *IC1Chaparda >;8tu1mca;blo8spot;com@ 3repared *: *har8a /aja8or
8/10/2019 All Unix Practical Programs
9/23
UNIX Shell Script
cd WW
O) echo $nter to Ble name to cop read f\name= f\name2 cp f\name= f\name2 WW Q) echo $nter Ble name to rename read fname m fname WW
J) echo $nter Ble name to delete
read fname rm fname
WW H) echo $nter Ble name to edit read fname i fname WW
4) echo Fou h entered ron8 choice WWesac
(=O) Mrite a script hich reads a te-t Ble and output the folloin8Count of character,ords and lines;ile in reerse;reEuenc of particular ord in the Ble;&oer case letter in place of upper case letter;
echo !0n $nter ilename : !read Blenecho !11111111111111111111111111111111111111111111111111111111111111!echo ! $NU !echo !11111111111111111111111111111111111111111111111111111111111111!echo ! a) Count the no; of char;s, ords, lines;!echo ! b) +ispla a Ble in reerse;!echo ! c) Count the no; of occurrences of a particular ord;!echo ! d) Conert &oer case to UppeCase!
*IC1Chaparda >;8tu1mca;blo8spot;com@ 3repared *: *har8a /aja8or
8/10/2019 All Unix Practical Programs
10/23
UNIX Shell Script
echo !11111111111111111111111111111111111111111111111111111111111111!echo !0n $nter Four Choice : !
read ccase !c! in a) echo !0n "otal lines,ords,char;s !
c BlenWW
b) re Blen K temp Gread buf
cat tempWW
c) echo !0n$nter ord to Bnd :! read for i in cat Blen do echo i KK f=;t-t done echo !"otal no; of ords< 0c! W
8rep 1c f=;t-t 8rep f=;t-t rm f=;t-t
WWd)
echo !See Blen Ble for output;;;! tr >a1@ >A1T@ P Blen
WW 4) echo !Inalid choice!
esac
(=Q) Mrite a shell script to chec9 hether the named user is currentl lo88edin or not;echo !enter user name!
read n
ho 6 8rep !]n!
if > ^ 1eE ? @
=? *IC1Chaparda >;8tu1mca;blo8spot;com@ 3repared *: *har8a /aja8or
8/10/2019 All Unix Practical Programs
11/23
UNIX Shell Script
then echo !currentl lo8 in!
else echo !not lo8 in!B
(=J) Mrite a Script for Simple +atabase ana8ement Sstem 'peration;
+atabase ile Contains olloin8 ields;
$3\N'$3\NA$$3\A++/$SS$3\AD$$3\D$N+$/$3\+$SIDNA"I'N$3\*ASIC\SA&A/F
3roide enu +rien acilit or
%I$M /$C'/+ *AS$+ 'N _U$/FA++ /$C'/++$&$"$ /$C'/+'+IF /$C'/+;C'UN" "'"A& NU*$/ ' /$C'/+S$XI"
>ma9e a Ble $mp;t-t ith folloin8 data$3\N':$3\NA$:$3\A++/$SS:$3\AD$:$3\D$N+$/:$3\+$S
IDNA"I'N:$3\*ASIC\SA&A/F@Ge-ec cat $mp;t-tch ch < !! @doecho !A%AI&A*&$ C#'IC$S::!echo !=;Add Ne /ecord::!
== *IC1Chaparda >;8tu1mca;blo8spot;com@ 3repared *: *har8a /aja8or
8/10/2019 All Unix Practical Programs
12/23
UNIX Shell Script
echo !2;%ie /ecord::!echo !L;odif /ecord::!
echo !;Count total number of records::!echo !O;$-it::!echo !$nter ou choice::!read nocase no in
=)len8
8/10/2019 All Unix Practical Programs
13/23
UNIX Shell Script
BB
WW
L)len empno 18t ((len1=)) 1o empno 1lt = @
thenecho !$ntered +ata is not aailable for odiBcation!
e-itelse
cur
8/10/2019 All Unix Practical Programs
14/23
UNIX Shell Script
read eadd echo !enter $mp A8e ::!
read ea8e echo !enter $mp Dender::! read e8en echo !enter $mp +esi8ation! read edes echo !eneer $mp *asic Salar ! read esal
echo empno:ename:eadd:ea8e:e8en:edes:esal KKtemp=;t-t
B
doneBne
8/10/2019 All Unix Practical Programs
15/23
UNIX Shell Script
/$%$/S$ "#$ S"/IND;
hile truedoecho 111111111111111111111111111111111111111echo =:C'3A/$ "M' S"/INDSecho 2:`'IN "M' S"/INDSecho L:IN+ "#$ &$ND"# ' A DI%$N S"/INDecho :'CCU//$NC$ ' C#A/AC"$/ AN+ M'/+Secho O:/$%$/S$ "#$ S"/INDecho 111111111111111111111111111111111111111echo $nter Choice:
read checho 111111111111111111111111111111111111111case ch in
=) echo $nter Strin8=: read str= echo $nter Strin82: read str2
if > str= < str2 @ then echo Strin8 is eEual else echo Strin8 is not eEual B WW2) echo $nter Strin8=:
read str= echo $nter Strin82: read str2
strL
8/10/2019 All Unix Practical Programs
16/23
UNIX Shell Script
echo $nter Strin8=: read str=
len8th
8/10/2019 All Unix Practical Programs
17/23
UNIX Shell Script
esacecho +o u ant to continue^
read ans if > ans < n @ then e-it Bdone
=; Mrite a script to calculate 8ross salar for an number of emploeesDross Salar
8/10/2019 All Unix Practical Programs
18/23
UNIX Shell Script
+A
8/10/2019 All Unix Practical Programs
19/23
UNIX Shell Script
reno
8/10/2019 All Unix Practical Programs
20/23
UNIX Shell Script
(2) Mrite a script to displa the last modiBed Ble;
echo !&ast modiBed Ble!Bles
8/10/2019 All Unix Practical Programs
21/23
UNIX Shell Script
(2O) Mrite a shell script to add the statement Ginclude Pstdio;hK at thebe8innin8 of eer C source Ble in current director containin8 printf and
fprintf;
echo !Incluede line GincludePstdio;hK in all c Ble!cile iCount pCount 18t ? 1a fCount 18t ? 1a iCount 1eE ? @ then rm tempc echo str K tempc cat i KK tempc rm i cp tempc i Bdone
(2Q) Mrite a script that behaes both in interactie and non1interactie mode;Mhen no ar8uments are supplied, it pic9s up each C pro8ram from currentdirector and lists the Brst =? lines; It then prompts for deletion of the Ble; Ifthe user supplies ar8uments ith the script, then it or9s on those Bles onl;echo !3erform operation as per passed ar8ument!totalAr8 totalAr8 1eE ? @then echo !No ar8ument supplied!
cilesFes:F6No:N@! read ch if > !ch! < !F! 1o !ch! < !! @
2= *IC1Chaparda >;8tu1mca;blo8spot;com@ 3repared *: *har8a /aja8or
8/10/2019 All Unix Practical Programs
22/23
UNIX Shell Script
then echo !User ant to delete this Ble! i
rm 1i i else echo !User +oes not ant to delete Ble! i B doneelse if > 1f = @ then echo !ile $-ist!
i =
else echo !ile does not $-ist! BB
(2J) Mrite a script that deletes all leadin8 and trailin8 spaces in all lines in aBle; Also remoe blan9 lines from a Ble; &ocate lines containin8 onl printf butnot fprintf;
echo !/emoe all leadin8 and trailin8 space alon8 ith blan9 lines from a8ienecho !$nter Ble name!read fName
if > 1f fName @then G delete *'"# leadin8 and trailin8 hitespace from each line sed s5]> 0t@455Ws5> 0t@455W fName Ktemp sed 5]5d temp m temp fName Gremoe all blan9 lines from a BleG sed 5]5d fNameelse
22 *IC1Chaparda >;8tu1mca;blo8spot;com@ 3repared *: *har8a /aja8or
8/10/2019 All Unix Practical Programs
23/23
UNIX Shell Script
echo !ile does not e-ist!B
2L *IC1Chaparda >;8tu1mca;blo8spot;com@ 3repared *: *har8a /aja8or