Linux Lab3
Linux Lab3
#!/bin/bash
done
-----
How to put output of a command in variable
------------------------------------------
var=$(command)
Concept
--------
If the command o/p is null the variable will be blank or 0, else it will be non
zero
##This script will ask for username and print its username:userid
#concepts to learn in this script
#you will get to now how scripts take input from user
#you will get to know how to put command's o/p in a variable
#you will get to know the usage of if-else loop
#you will get to learn the logic of writing a script
#you will get to know the file for user info
if [[ -n $myvar ]]
then
echo "$myvar"
else
echo "user not found"
fi
Alias command
-------------
used to give canonical names to the commands
for ex: ll is also ls -l
-------
[root@localhost ~]# alias scr='ls /root/editiss/scripts'
[root@localhost ~]# scr
for.sh script1.sh user-id-info.sh
-------
[Aman G] 9516688917
useradd in Ubuntu - because it does not create home for that user.
-----------------------------------------------------------------
Create a script that asks for a path and tell if the entered path is a file or
directroy or doesnt exist.
if [[ -f $path ]]
then
echo "$path --> file"
elif [[ -d $path ]]
then
echo "$path --> directory"
else
echo "$path --> invalid"
fi
--
[Vrushali] https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
To find out if a package is installed or not on the system - we use command: rpm -
qa | grep <package name>
q - query
a - all
so , it queries amongst all the installed packages and finds your own package
[Assignment Ques]
1. Write a script that performs following operations on the given set of files?
msexchange.qlv
Necessary Compliance Violations.docx
New Doc 12-23-2020 16.51.pdf
Open Cases.csv
OPS-94632_new.tar
OS-Windows.pdf
QQL.json
Ransomware.docx
Red_Hat Reference Guide.pdf
Script Analysis.xlsx
Script page.jpg
SolarWinds_Supply-Chain_Attack_UDdashboard.json
Splunk_PC_App.png
Splunk_VM_App.png
Studio_Malware_July_2013.xlsx
Troubleshooting Agent Permission Issues for Windows.pdf
UDC_Demo_20210106.xml
Video 2020-11-10 at 7.12.43 PM.mp4
VMware-workstation-full-15.5.5-16285975.exe
VMware-workstation-full-16.0.0-16894299.exe
WhatsApp Image 2020-11-05 at 2.47.06 PM.jpeg
win.txt
2. Write a script that displays the user information on the linux box in the
following format:
Username Shell assigned to that user
3. Create ascript that asks for a username and displays it's group name
4. Create a script that asks for a file name and dislays its permission
5. Create a script that asks for a directory name and dislays its permission
6. Create a script that displays only those users whose UID > 1000
7. Create a script that asks for username and checks if that user is a sudoer
8. Create a script that asks for a processname and didplays it's PID
9. Create a script that:
- creates a dir 'test' with 100 files in it 'file{1..100}'
- provides executable permissions to others for file 1-50
- displays the name of all world executable files
- changes their permission to world-readable only
- displays the name of all world readable files woith permissions
10. Create a script that asks for a username and displays all the files owned by
that user.