Sunteți pe pagina 1din 12

Name-Muskan Agarwal

Assignment-1
Codingclub
Question-1

a. cat /etc/passwd
b. cat /etc/passwd | awk -F: '{print $1}'
c. cat passwd.txt | awk -F: '{if($3>1000) print $3}'
d. cat passwd.txt | awk -F: '{print $6}'
Question-2

i) for file in `ls *.txt`;


do
folderName=`echo $file |awk -F. '{print $1}'`;
if [ -d $folderName ];
then
echo Removing folder $folderName as it already exists
rm -R $folderName;
fi
mkdir $folderName;
echo Moving $file to $folderName
mv $file $folderName;
echo moved $file to $folderName;
done

Moving abc.txt to abc


moved abc.txt to abc
Moving def.txt to def
moved def.txt to def
Moving ghi.txt to ghi
moved ghi.txt to ghi
Moving jkl.txt to jkl
moved jkl.txt to jkl
Question-3

#!/bin/bash

for files in `ls *.log.1`


do
status=$?
if [ $status -ne 0 ]
then
echo "No files with extension log.1"
fi
fileName=`echo $files | awk -F. '{print $1}'`
echo "Renaming file $files"
TodayDate=`date +%d%m%Y`
newFile="$fileName-$TodayDate.log.1"
mv $files $newFile
done

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1/Temp


$ ./AppendCurrentDateToLogFiles.sh
Renaming file abc.log.1
Renaming file def.log.1
Renaming file ghi.log.1
Renaming file jkl.log.1
Renaming file lmn.log.1

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1/Temp


$ ls
abc-28062020.log.1 def-28062020.log.1 jkl-28062020.log.1
AppendCurrentDateToLogFiles.sh* ghi-28062020.log.1 lmn-28062020.log.1
Question-4

#!/bin/bash

for files in `find /var/log -mtime +7 -type f`


do
cp $files /var/log/backup/
echo "Moving $files to backup folder"
done

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1


$ ./ArchiveFilesModified7daysAgo.sh
Moving ../linux-content/.git/config to backup folder
Moving ../linux-content/.git/description to backup folder
Moving ../linux-content/.git/HEAD to backup folder
Moving ../linux-content/.git/hooks/applypatch-msg.sample to backup folder
Moving ../linux-content/.git/hooks/commit-msg.sample to backup folder
Moving ../linux-content/.git/hooks/fsmonitor-watchman.sample to backup folder
Moving ../linux-content/.git/hooks/post-update.sample to backup folder
Moving ../linux-content/.git/hooks/pre-applypatch.sample to backup folder
Moving ../linux-content/.git/hooks/pre-commit.sample to backup folder
Moving ../linux-content/.git/hooks/pre-push.sample to backup folder
Moving ../linux-content/.git/hooks/pre-rebase.sample to backup folder
Moving ../linux-content/.git/hooks/pre-receive.sample to backup folder
Moving ../linux-content/.git/hooks/prepare-commit-msg.sample to backup folder
Moving ../linux-content/.git/hooks/update.sample to backup folder
Moving ../linux-content/.git/index to backup folder
Moving ../linux-content/.git/info/exclude to backup folder
Moving ../linux-content/.git/logs/HEAD to backup folder
Question-5

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1


$ egrep -o 'https?://[^\)"]+' access.log | sort | uniq -c | sort -nr |head -4

1475 https://fundoopush-dev.bridgelabz.com/login
1141 https://fundoopush-dev.bridgelabz.com/dashboard/article
176 https://fundoopush-dev.bridgelabz.com/add-post
74 http://www.google.com/bot.html

Question-6

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1


$ timestamp="21/Sep/2019:06:31:06"
Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1
$ cat access.log | grep "$timestamp" | egrep -o 'https?://[^\)"]+' | sort |
uniq -c | sort -nr
3 https://fundoopush-dev.bridgelabz.com/dashboard/article
Question-7

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1


$ timestamp="21/Sep/2019:06:31:06"
Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1
$ cat access.log | grep "$timestamp" | awk -F\" '{print $3}' | awk '{print $1}' |
sort | uniq -c | sort -nr

3 200

Question-8

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1


$ timestamp="21/Sep/2019:06:31:06"
Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1
$ cat access.log | grep "$timestamp" | awk -F\" '{print $1}' | awk '{print $1}' |
sort | uniq -c | sort -nr

3 10.56.2.2
Question-9

read -p "Enter the name of folder you want to make " folderName
if [ -d $folderName ]
then
echo "Folder already exists"
else
mkdir $folderName
echo "Making directory $folderName"
fi
Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1
$./FolderExistsOrNot.shell
Enter the name of folder you want to make Temp
Making directory Temp

Question-10

list=`ls`
status=$?
if [ $status -eq 0 ]
then
echo "ls command executed successfully"
else
echo "ls command not executed successfully"
fi
list=`hello`
status=$?
if [ $status -eq 0 ]
then
echo "hello command executed successfully"
else
echo "hello command not executed successfully"
fi
___________________________________________________________________________
Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1
$ ./checkExecutionStatus.shell
ls command executed successfully
./checkExecutionStatus.shell: line 9: hello: command not found
hello command not executed successfully
Question-11

#!/bin/bash

case "$usersecret" in
"") echo "setting environment variable to dH34xJaa23"
usersecret='dH34xJaa23'
;;
*) echo "Environment variable already set"
;;
esac

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1


$ ./EnvironmentVariable.sh
setting environment variable to dH34xJaa23

Question-12

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1/systemd


$ grep -c -R 'systemd'

1.log:4
2.log:6
3.log:11
Question-13

ps -eo pid,ppid,cmd,%mem%cpu

“-o” flag is not supported in git bash so won’t be able to get the output of the above
command.
Question-14

i) cat data.csv | awk '{if($4>10000) print $2,$7}'

EmployeeName TotalPay
NATHANIEL 567595
GARY 538909
ALBERT 335279
CHRISTOPHER 332343
PATRICK 326373
DAVID 316285
Question-15

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1


$ diff -qr original/ updated/
Only in original/: original-file.sh
Only in updated/: updated.sh

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1


$ cp -avr original/ original-backup
'original/' -> 'original-backup/original'
'original/original-file.sh' -> 'original-backup/original/original-file.sh'

Muskan@DESKTOP-EJUM3U4 MINGW64 ~/Desktop/LinuxLearning/Assignment 1


$ diff -qr updated/ original-backup/

S-ar putea să vă placă și