diff --git a/Sem1/Unix_Programming/script_10a.awk b/Sem1/Unix_Programming/script_10a.awk new file mode 100644 index 0000000..5a56858 --- /dev/null +++ b/Sem1/Unix_Programming/script_10a.awk @@ -0,0 +1,41 @@ +{ + split( $0, inpt, "-") + if ((inpt[1] < 1) || (inpt[1] > 31) || (inpt[2] < 1) || (inpt[2] > 12)) + { + print "Invalid Date!" + exit 0 + } + else + { + switch (inpt[2]) + { + case 1: print "Jan" + break + case 2: print "Feb" + break + case 3: print "Mar" + break + case 4: print "Apr" + break + case 5: print "May" + break + case 6: print "Jun" + break + case 7: print "Jul" + break + case 8: print "Aug" + break + case 9: print "Sep" + break + case 10: print "Oct" + break + case 11: print "Nov" + break + case 12: print "Dec" + break + } + print inpt[1] + print inpt[3] + exit 0 + } +} diff --git a/Sem1/Unix_Programming/script_10b.awk b/Sem1/Unix_Programming/script_10b.awk new file mode 100644 index 0000000..34be5f4 --- /dev/null +++ b/Sem1/Unix_Programming/script_10b.awk @@ -0,0 +1,27 @@ +BEGIN{ + printf("\nOriginal FIle\n") + i=1 +} +{ + print $0 + line[i++]=$0 +} +END{ + for(j=1; j= 10000 ) + { + da=0.45*$5; da_tot+=da; + hra=0.15*$5;hra_tot+=hra; + } + else + { + da=0.50*$5;da_tot+=da; + hra=0.20*$5;hra_tot+=hra; + } + sal_tot+=$5 + da + hra + printf("%2d\t%-15s %12-s %8d %8.2f %8.2f %8.2f\n",slno,$2,$3,$5,da,hra,$5+da+hra) +} +END{ + printf( "\n\ttotal basic paid is : rs " basic_tot) + printf( "\n\ttotal da paid is : rs " da_tot) + printf( "\n\ttotal hra paid is : rs " hra_tot) + printf( "\ntotal salary paid is : rs " sal_tot) + printf("\n") +} diff --git a/Sem1/Unix_Programming/script_1a.sh b/Sem1/Unix_Programming/script_1a.sh new file mode 100644 index 0000000..4d5c751 --- /dev/null +++ b/Sem1/Unix_Programming/script_1a.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +if [ $# -eq 1 ] +then + if [ -e $1 ] + then + echo "Larget File in the directory: $(find $1 -printf '%k %p\n' | sort -nr | head -n 1 | cut -d " " -f 2)" + + else + echo "Path does not exist! Please check the path." + exit 0 + fi +else + echo "This script takes only one valid directory name as an arguement!" +fi diff --git a/Sem1/Unix_Programming/script_1b.sh b/Sem1/Unix_Programming/script_1b.sh new file mode 100644 index 0000000..a69d1b5 --- /dev/null +++ b/Sem1/Unix_Programming/script_1b.sh @@ -0,0 +1,9 @@ +#! /bin/bash + +if [ $# -eq 1 ] +then + mkdir -pv $1 +else + echo "This Script is only programmed to take one arguement as an input!" +fi + diff --git a/Sem1/Unix_Programming/script_2a.sh b/Sem1/Unix_Programming/script_2a.sh new file mode 100644 index 0000000..c74eccf --- /dev/null +++ b/Sem1/Unix_Programming/script_2a.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +if [ $# -eq 2 ] +then + + PERM1=$(stat --printf=”%a” $1) + PERM2=$(stat --printf=”%a” $2) + + if [ "$PERM1" = "$PERM2" ] + then + echo Both the files have same permissions: $(stat --printf="%A" $1) + else + echo The given files have different permissions + echo "$1 : $(stat --printf="%A" $1)" + echo "$2 : $(stat --printf="%A" $2)" + fi +else + echo "This script is programmed to use two files in order + to compare their permissions" + +fi + diff --git a/Sem1/Unix_Programming/script_2b.sh b/Sem1/Unix_Programming/script_2b.sh new file mode 100644 index 0000000..4975ef4 --- /dev/null +++ b/Sem1/Unix_Programming/script_2b.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +if [ $# -eq 0 ] +then + echo "Run this script with one or more username(s) as arguement!" +else + for i in $* + do + if [ $(grep $i /etc/passwd) ] + then + echo "Home directory for $i: " + eval "echo ~$i" + else + echo "user does not exsist" + fi + done +fi diff --git a/Sem1/Unix_Programming/script_3a.sh b/Sem1/Unix_Programming/script_3a.sh new file mode 100644 index 0000000..51fe384 --- /dev/null +++ b/Sem1/Unix_Programming/script_3a.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +if [ $# -ne 1 ] +then + echo "Run this cript with only one filename as arguement!" +else + if [ -f "$1" ] + then + echo "Name : $1" + echo "Permissions : $(stat --format="%A" $1)" + echo "Type: $(stat --format="%F" $1)" + echo "Owner: $(stat --format="%U" $1)" + echo "Group: $(stat --format="%G" $1)" + echo "Size: $(stat --format="%s" $1)" + else + echo "File does not exsist" + fi +fi diff --git a/Sem1/Unix_Programming/script_3b.sh b/Sem1/Unix_Programming/script_3b.sh new file mode 100644 index 0000000..16e29bb --- /dev/null +++ b/Sem1/Unix_Programming/script_3b.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +while true +do + clear + echo "**Password entered will not visible for security reasons**" + echo "Enter Password: " + read -s passFirst + echo "Re-enter Password: " + read -s passConfirm + + if [ "$passFirst" = "$passConfirm" ] + then + clear + echo "Terminal Locked !" + stty intr '' + stty eof '' + stty kill '' + stty stop '' + stty susp '' + echo "To unlock, Enter Password: " + passFirst="" + until [ "$passFirst" = "$passConfirm" ] + do + read -s passFirst + done + stty intr '^C' + stty eof '^D' + stty kill '^U' + stty stop '^S' + stty susp '^Z' + echo "Terminal Unlocked !" + exit + else + echo "Password Mismatch !" + sleep 3 + fi +done diff --git a/Sem1/Unix_Programming/script_4a.sh b/Sem1/Unix_Programming/script_4a.sh new file mode 100644 index 0000000..97fa4aa --- /dev/null +++ b/Sem1/Unix_Programming/script_4a.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +if [ $# -eq 0 ] +then + echo "This script requires atleast one filename as arguement" +else + for i in $* + do + if [ -f $i ] + then + tr '[a-z]' '[A-Z]' < $i>tempFile + mv tempFile $i + echo "File $i has been translated." + else + echo "$i does not exist in the current directory" + exit 1 + fi + done +fi diff --git a/Sem1/Unix_Programming/script_4b.sh b/Sem1/Unix_Programming/script_4b.sh new file mode 100644 index 0000000..0af1ac1 --- /dev/null +++ b/Sem1/Unix_Programming/script_4b.sh @@ -0,0 +1,32 @@ +clear + +if [ $# -eq 0 ] +then + printf "Invalid arguments" +else + if [ $# -eq 1 ] + then + dir=`pwd` + elif [ $# -eq 2 ] + then + dir=$2 + fi + +if [ -f $1 ] +then + inode=`ls -i $1 | cut -d " " -f 1` + printf "hard link of $1 are:\n" + find $dir -inum $inode + find $dir -type l -ls |tr -s " " |grep $1 |cut -d " " -f 12 > soft + s=`wc -l < soft` + if [ $s -eq 0 ] + then + echo "There is no soft links" + else + echo "Soft links of $1 are" + cat soft + fi +else + printf "file doesn't exist" +fi +fi diff --git a/Sem1/Unix_Programming/script_5a.sh b/Sem1/Unix_Programming/script_5a.sh new file mode 100644 index 0000000..a4651e5 --- /dev/null +++ b/Sem1/Unix_Programming/script_5a.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if [ ! -f "$1" ] || [ $# -ne 1 ] +then + echo "This script only accepts one valid filename as arguement!" +else + statLAT=$(stat --printf "%x" $1) + lat=$(date --date="$statLAT" +"%d/%m/%Y %I:%M %p") + echo "FileName: $1" + echo "Last Access Time: $lat" +fi diff --git a/Sem1/Unix_Programming/script_5b.sh b/Sem1/Unix_Programming/script_5b.sh new file mode 100644 index 0000000..aedd644 --- /dev/null +++ b/Sem1/Unix_Programming/script_5b.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +echo "Current Date: $(date +"%d/%m/%Y")\n" +currDate=$(date +"%d") +if [ $currDate -le 9 ] +then + currDate=$(echo $currDate | cut -f 2) + echo "$(ncal | sed 's/\b'"$currDate"'\b/'*'/')" +else + echo "$(ncal | sed 's/\b'"$currDate"'\b/'**'/')" +fi + diff --git a/Sem1/Unix_Programming/script_6a.sh b/Sem1/Unix_Programming/script_6a.sh new file mode 100644 index 0000000..0462ed4 --- /dev/null +++ b/Sem1/Unix_Programming/script_6a.sh @@ -0,0 +1,17 @@ +#!/bin/bash +if [ $# -eq 0 ] +then + echo “No arguments” + exit +else + list=$(grep -rwlc "$1" *) + if [ $? -eq 0 ] + then + for x in $list + do + echo "Filename: $x" + cat $x + cp -v $x ~/mydir + done + fi +fi diff --git a/Sem1/Unix_Programming/script_6b.sh b/Sem1/Unix_Programming/script_6b.sh new file mode 100644 index 0000000..2dee874 --- /dev/null +++ b/Sem1/Unix_Programming/script_6b.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +currentDir=$(pwd) +listOfFiles=$(ls -l "$currentDir" | awk '{print $9}') +echo "Current Directory: $currentDir" +echo "All files whose filename is at least 10 characters: " +for f in $listOfFiles +do + if [ $(expr length "$f") -gt 10 ] + then + echo $f + fi +done diff --git a/Sem1/Unix_Programming/script_7a.sh b/Sem1/Unix_Programming/script_7a.sh new file mode 100644 index 0000000..a67435b --- /dev/null +++ b/Sem1/Unix_Programming/script_7a.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +currentTime=$(date +"%H") +if [ $currentTime -ge 00 ] && [ $currentTime -le 11 ] +then + echo "Good Morning!" +elif [ $currentTime -ge 12 ] && [ $currentTime -le 14 ] +then + echo "Good Afternoon!" +elif [ $currentTime -ge 15 ] && [ $currentTime -le 18 ] +then + echo "Good Evening!" +else + echo "Good Night!" +fi diff --git a/Sem1/Unix_Programming/script_7b.sh b/Sem1/Unix_Programming/script_7b.sh new file mode 100644 index 0000000..fdaee6d --- /dev/null +++ b/Sem1/Unix_Programming/script_7b.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +if [ $# -lt 2 ] +then + echo "This script takes in two filenames as arguements" + exit +else + string1=`cat $1 | tr '\n' ' '` + for (( i=2; i<=$#; i++ )) + do + echo "Filename: ${!i}" + for a in $string1 + do + echo "$a: `grep -c "$a" "${!i}"`" + done + done +fi + diff --git a/Sem1/Unix_Programming/script_8a.sh b/Sem1/Unix_Programming/script_8a.sh new file mode 100644 index 0000000..5428b3a --- /dev/null +++ b/Sem1/Unix_Programming/script_8a.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +if [ $# -ne 1 ] +then + echo "This script takes one username as arguement!" + exit +else + if [ $(grep -c $1 /etc/passwd) -ne 0 ] + then + if [ $(last -Fw|grep -c $1) -ne 0 ] + then + loginDate=$(last -Fw |grep $1 | head -1 | tr -s " " | awk '{printf("%s %s %s %s\n",$5,$6,$7,$8)}') + loginDate=$(date -d "$loginDate" "+%s") + currDate=$(date "+%s") + sessionTime=$((currDate-loginDate)) + sday=$(( sessionTime/86400 )) + shour=$(( (sessionTime-(sday*86400))/3600 )) + smin=$(( (sessionTime-(sday*86400)-(shour*3600))/60 )) + ssec=$(( (sessionTime-(sday*86400)-(shour*3600)-(smin*60)) )) + printf "Active Session Time: %02d days %02d hours %02d mins %02d secs\n" "$sday" "$shour" "$smin" "$ssec" + + else + echo "The user has no recent logins" + exit + fi + else + echo "Invalid Username!" + exit + fi +fi diff --git a/Sem1/Unix_Programming/script_8b.sh b/Sem1/Unix_Programming/script_8b.sh new file mode 100644 index 0000000..5938546 --- /dev/null +++ b/Sem1/Unix_Programming/script_8b.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +if [ $# -ne 1 ] +then + echo "This script requires only one username as arguement" + exit +else + startTime=$(date -d "now" "+%s") + until who|grep -sw "$1" + do + curTime=$(date -d "now" "+%s") + if [ $(( $curTime-$startTime )) -ge 90 ] + then + echo "Timed Out!" + exit + fi + done + echo "User $1 logged in !" + exit +fi + diff --git a/Sem1/Unix_Programming/script_9a.sh b/Sem1/Unix_Programming/script_9a.sh new file mode 100644 index 0000000..614f1c1 --- /dev/null +++ b/Sem1/Unix_Programming/script_9a.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +if [ $# -ne 3 ] +then + echo "This script requires three arguemnts! FileName,Starting Line Number and Ending Line Number" + exit +else + if [ -f $1 ] + then + eval "sed -n $2,$3\p $1" + exit + else + echo "No Such File!" + exit + fi +fi + diff --git a/Sem1/Unix_Programming/script_9b.sh b/Sem1/Unix_Programming/script_9b.sh new file mode 100644 index 0000000..55c2464 --- /dev/null +++ b/Sem1/Unix_Programming/script_9b.sh @@ -0,0 +1,17 @@ +#!/bin/bash +if [ $# -ne 1 ] +then + echo "This script takes in only one filename as arguement!" + exit 1 +else + if [ -f $1 ] + then + echo "**ORIGINAL FILE**" + cat $1 + printf "\n" + echo "**FOLDED FILE**" + fold -s -w 40 $1 | sed 's/$/\//' + else + echo "file doesn't exist" + fi +fi