Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I created this script that basically will email me whenever anyone installs a thumbdrive, external HD, etc. in one of the servers. But I can't get the thing to work it always emails BAD. I have copied from the screen or from the HD.txt file and neither work.
Thanks to all in advance.
=========================
lsblk -io KNAME,TYPE,SIZE,MODEL > HD.txt ## gets all HDs & partitions in system
sed -i -r 's/\s+//g' HD.txt ## removes whitespace
sed -i ':a;N;$!ba;s/\n/XX/g' HD.txt ## remove carriage returns and replaces with XX
# Edit HD.txt to insert in the value below
PARTITIONS1="KNAMETYPESIZEMNODEL?sdadisk149.1GST3160318AS?sda1part500M?sda2part27.5G?dm-0crypt27.5G?dm-1lvm25.5G?dm-2lvm2G?sr0rom1024MDVDCDH48C2S"
PARTITIONS2=$(cat HD.txt)
if [[ $PARTITIONS1 == $PARTITIONS2 ]]
then
echo "Good"
else
echo "BAD on `hostname`" |mail -s "BAD on `hostname`" root &
fi
change the script so that it outputs the 2 variables, and compare them manually.
also i'm pretty sure you have to put doublequotes around them (and some other places in the script).
SOLVED... typos on my part here is a debug version edit to your own taste.
lsblk -io KNAME,TYPE,SIZE,MODEL > HD.txt ## gets all HDs & partitions in system
sed -i -r 's/\s+//g' HD.txt ## removes whitespace
sed -i ':a;N;$!ba;s/\n/XX/g' HD.txt ## remove carriage returns and replaces with XX
# Edit HD.txt to insert in the value below
PARTITIONS1="KNAMETYPESIZEMODELXXsdadisk149.1GST3160318ASXXsda1part500MXXsda2part27.5GXXdm-0crypt27.5GXXdm-1lvm25.5GXXdm-2lvm2GXXsr0rom1024MDVDCDH48C2S"
PARTITIONS2=$(cat HD.txt)
if [[ $PARTITIONS2 == $PARTITIONS1 ]]
then
echo "Good"
else
echo $PARTITIONS1
echo $PARTITIONS2
echo "BAD on `hostname`" |mail -s "BAD on `hostname` `date`" root &
echo "put your coding in here to destroy (shred, wipe, etc) USB or HD or whatever someone is using in your server to steal your stuff. NOTE in GRUB if you are not on a server with a USB keyboard put in "nousb" at the end of the kernel line so no usb anything works."
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.