• We did not send an email asking for donations - please read this post.

Linux.org User-created Helpful Shell Scripts

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,996
Reaction score
3,642
Credits
36,416
Yes I tested it but replaced the destruction command with another command and it works as expected. You can remove it, it was just for the laughs.
 


CrazedNerd

Well-Known Member
Joined
Mar 31, 2021
Messages
822
Reaction score
321
Credits
7,012
I kinda want to remove that script - but you DID warn 'em.

Note: New users, do not run the script in this post:


Also, I wonder if @f33dm3bits tested the script before sharing it?
I wish there was a forum specifically for posting viruses f33's, comes pretty close! Not for financial/black-hat reasons but for creating visible havock on virtual machines or empty computers, i've seen a couple of youtube videos which contain that...
 

Dart

Member
Joined
Jan 5, 2022
Messages
66
Reaction score
61
Credits
786
Well... I do have some practical scripts that could be used every day. One in particular, a window manager. However, it's not for the timid. It requires ksh, wmctrl, xwininfo and xdotool. (It'll let you know if they're not installed). Also, you'll need to set up keyboard shortcuts. It has seventeen options of which some can be added together.

It will figure out (pretty closely) the size of the top and bottom panels, then calculate the screen size without the panels. It works fairly good, but may need tweaking. I need to work in it a bit more. I've been using it for over 10 years. Since I was the only one using it, I didn't bother to flush it out. Now that there's some place someone may use it. I think it's time to finish it up.

The first several installations of it were on Red Hat based Linux. I installed it on my current machine running Manjaro about 5 years ago. It didn't need any tweaking other than installing the afore mentioned tools, so I'm hoping other distros will play nicely with it as well... Hopefully, we'll see.

To give an idea of what it does, Here's a couple of the functions.
# A brief explanation.
usage(){
echo
echo "Options:"
echo " -8 80x25(roughly) Window size."
echo " -a Manipulate the active window. (Default)"
echo " -b When resizing a window's height specify that it is to"
echo " use the bottom half of the screen, top is the default."
echo " -c Centers the window."
echo " -d Resizes window to full width."
echo " -f Resizes window to full height."
echo " -l Move window to the left of the screen."
echo " -r Move window to the right of the screen. (Working, kind of.)"
echo " -s Forces the user to select a window to manipulate."
echo " -t Resize a window to half the height of the current desktop."
echo " -w Resize a window to half the width of the current desktop."
echo " -u Places window at the top of the destkop."
echo " -h This help."
echo
echo
echo "Some Common options."
echo "Half screen window right: wm_ctrl.sh -warf"
echo "Half screen window left: wm_ctrl.sh -walf"
echo "Move window to the top: wm_ctrl.sh -u"
echo "Move window to the bottom: wm_ctrl.sh -b"
echo "Move window to the right: wm_ctrl.sh -r"
echo "Move window to the left: wm_ctrl.sh -l"
echo "Resize window to 1/3rd width: wm_ctrl.sh -1"
echo "Resize window to 2/3rd width: wm_ctrl.sh -2"
echo "Resize window to half width: wm_ctrl.sh -wa"
echo "Resize window to half height: wm_ctrl.sh -t"
echo "Center window in both directions: wm_ctrl.sh -C"
echo "Center window horizontally: wm_ctrl.sh -c"
exit 0
}
###########################################################################
# Main
###########################################################################
while getopts 1238abCcdflrstuwh opt
do
case "$opt" in
1) wd="$w13";;
2) wd="$w23";;
3) wd="$fw";;
# Approx 80x25 sizing.
8) wd=`echo "scale=5 ; $wm_wd * .427604167" | bc -l | xargs printf "%1.0f\n" ` ;
wh=`echo "scale=5 ; $wm_hi * .513238289" | bc -l | xargs printf "%1.0f\n"`;;
a) wtype=":ACTIVE:";;
b) hpos="$(($hh+$offset))";;
C) hpos=`echo "scale=0; ($wm_hi/2)-($win_hi/2)+$offset" | bc -l`
vpos=`echo "scale=0; ($wm_wd/2)-($win_wd/2)" | bc -l`;;
c) vpos=`echo "scale=0; ($wm_wd/2)-($win_wd/2)" | bc -l`;;
d) wd="$wm_wd";;
f) wh="$wm_hi";;
l) vpos="0";;
r) vpos=`echo "$wm_wd-$win_wd" | bc -l`;;
s) wtype=":SELECT:";;
t) wh="$(($hh-22))";;
u) hpos="0";;
w) wd="$hw";;
h|*) usage;;
esac
done
###########################################################################
# Do the work! ;)
###########################################################################
wmctrl -r "$wtype" -e 0,"$vpos","$hpos","$wd","$wh"
 

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,996
Reaction score
3,642
Credits
36,416
OP
K

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
7,432
Reaction score
6,405
Credits
60,265
I also tested the script with the desctruct command in a vm and it works as expected there as well, causing my vm's installation to be destroyed.

It's good to be thorough!
 

CrazedNerd

Well-Known Member
Joined
Mar 31, 2021
Messages
822
Reaction score
321
Credits
7,012
Here's an alias for taking files that are being created/used by software on your computer, and putting those files in a more convenient place for personal access:

Code:
alias organize='find <top-folder> -maxdepth <number> -mindepth <number> -type d -exec cp -r {} <destination> \;'

find here is configured to take folders from an exact depth, and then those folders are given to cp and put into a more favorable place (use the same number for maxdepth and mindepth to specify an exact depth). I'm so happy that i actually figured out how to use the -exec option today!
 

Dart

Member
Joined
Jan 5, 2022
Messages
66
Reaction score
61
Credits
786
alias organize='find <top-folder> -maxdepth <number> -mindepth <number> -type d -exec cp -r {} <destination> \;'
Nice script. Try using rsync. It will preserve the date and time stamps and much much more. That, and if your into learning, it's a worm hole all it's own. It has over 100 options and can be used to transfer/copy to/from folder to folder and to and from other hosts. It could be used to replicate important data / folders etc.. from your machine to a backup computer for safe keeping.

Something like this.
Code:
find /util -maxdepth 0 -mindepth 0 -type d -exec rsync -avn {} /tmp/output/ \;

The n in avn is for a dry run. You can test your code and never write a byte. Remove the n to run it. The a = archive v = verbose (tells you what files are being copied & more)

Just a thought.
 

CrazedNerd

Well-Known Member
Joined
Mar 31, 2021
Messages
822
Reaction score
321
Credits
7,012
Nice script. Try using rsync. It will preserve the date and time stamps and much much more. That, and if your into learning, it's a worm hole all it's own. It has over 100 options and can be used to transfer/copy to/from folder to folder and to and from other hosts. It could be used to replicate important data / folders etc.. from your machine to a backup computer for safe keeping.

Something like this.
Code:
find /util -maxdepth 0 -mindepth 0 -type d -exec rsync -avn {} /tmp/output/ \;

The n in avn is for a dry run. You can test your code and never write a byte. Remove the n to run it. The a = archive v = verbose (tells you what files are being copied & more)

Just a thought.
Yeah rsync is a powrrful tool but i'm generally confused about practical ways to use it, the normal copy command is very easy to understand but i do want to have a better grasp of rsync.
 

CrazedNerd

Well-Known Member
Joined
Mar 31, 2021
Messages
822
Reaction score
321
Credits
7,012
Look up 'fork bomb', if you want some good old fashioned terminal fun.
Fork bomb is a pretty great system-destroyer...i tested it on an ubuntu VM today (live without install), and it took about 30 minutes before it made the system run so badly that i had to power off the machine. I think that's neat because not only could i keep entering {icode]free[/icode] to check on how much virtual RAM was getting used up, but it could also theoretically be used for "evil" purposes since it's kinda slow:

Code:
:(){ :|:& };:

here's where i cound this particular fork bomb:

 
OP
K

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
7,432
Reaction score
6,405
Credits
60,265
A word of caution... Do not run the above command unless you know what to expect. It's an amusing academic exercise that won't really break anything, but it will force a reboot.

That said, I wonder what made it take 30 minutes. It's usually much faster.

There are some great obfuscated fork bombs out there in like Perl.
 

CrazedNerd

Well-Known Member
Joined
Mar 31, 2021
Messages
822
Reaction score
321
Credits
7,012
A word of caution... Do not run the above command unless you know what to expect. It's an amusing academic exercise that won't really break anything, but it will force a reboot.

That said, I wonder what made it take 30 minutes. It's usually much faster.

There are some great obfuscated fork bombs out there in like Perl.
It might have been 15-20 minutes (never over-estimate my conception of time...) but i was happy that it was slow enough that i could keep running the "free" command to see the progress it was making. RIght off the bat, it was using less than 4GB of 8GB total RAM...it slowly made it's way up to 5GB, and then slowly made its way to giving me just a black screen that i couldn't click back into existence.

I should also noted that the output from the "free" command was not entirely linear, sometimes it was using less RAM than before, but it's clearly a virus-like type of command (that doesn't threaten your data unless you've got some outdated hardware...don't run with a bare metal machine with an HDD!) that slowly takes over and forces you to power-off your system.
 
OP
K

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
7,432
Reaction score
6,405
Credits
60,265
Oh, it shouldn't actually harm your data - not that one I don't think, even on real hardware. I wonder if the VM has something to do with it taking that long. The last time I ran it on a real computer it was that same command and it killed it pretty quickly. It wouldn't surprise me too much if it behaved differently on virtualized hardware. The VM's software may even try to prevent things like that.

Anyhow, we probably shouldn't veer too far from the topic in this thread, so I'll stop gabbing like an old lady across the fence.
 

CrazedNerd

Well-Known Member
Joined
Mar 31, 2021
Messages
822
Reaction score
321
Credits
7,012
Oh, it shouldn't actually harm your data - not that one I don't think, even on real hardware.
It could, theoretically, if you force the computer and that causes the needle to scratch the platter on an HDD...but other than that it shouldn't hard the integrity of files.
 

CrazedNerd

Well-Known Member
Joined
Mar 31, 2021
Messages
822
Reaction score
321
Credits
7,012
In the spirit of practical become "practical joke", here is something i made today that could be used on computer systems at work or some sort of family computer network. WIth crontab, this behaves like a loop so you don't have to do anything else. It's very light-hearted and g-rated :)

Code:
#!/bin/bash

FNAME=<insert-absolute-directory-path-to-new-filename-in-desktop>

if [ -e $FNAME ]; then

    echo -e "\n\nOkay I know i wasn't very specific, but I'm in your bathroom! Explain yourself!" >>  $FNAME

else

    echo -e "Dear Desktop User,\n I know about some things you did a very long time ago, and i also know about some other stuff too.\nGive me a million dollar by 5pm eastern standard time  or else there's gonna be some problems dude!" >> $FNAME

fi
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Top