Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Share your Scripts
New Posts  All Forums:Forum Nav:

Share your Scripts

post #1 of 305
Thread Starter 
Well, I am fairly new here, but I found the Linux area, and I see Linux, I will come smile.gif
Anyway, just an idea I had, for sharing our scripts that we've come up with, and hopefully I see a few that will make Windows users so jealous that they'll have no choice but to finally give up and raise their middle finger to Microsoft. Share what ever you want to share, no matter how big, small, simple, or complicated they are, but one rule, don't share a script as your own if you didn't actually write it, if it's not your script, and you share it, then give the original writer the credit they deserve, I know that my most used one, if it was ever claimed by someone else, well, I would want to do nasty things to that person. If you have ever spent days racking your brains how to get past a hurdle, to the point that your thinking about it even while your at the movies with your girlfriend on Valentines day, and the solution comes to you in a dream, well then you'll understand lol
Anyway, I'll start with my most usefull script, which also happens to be the one that I came up with myself too smile.gif It's still under development, on the ToDo list is :- Make it more system friendly with a single configuration file to specify variables so it can be implemented on any system, no matter what the folder structure is, merge all the other scripts that it calls into the one, and tidy up some of the code. Now this is my script, and I do give permission for anyone else to use it, modify it, share it, what ever you want to do with it, I just ask, that if you are sharing it with someone else, you me me the credit I deserve for it.

Contents of Multiple directory trees in one place.
Code:
#This script will scan a set of folders, and then symlink that folder structure in one place,
#perfect for your media collection that has to be stored across multiple drives, and you
#hate having to remember which drive it was on, and you dont have a raid setup.
#written by Adam Bielby, feel free to share, or modify as you please, just give me a mention ;)
tree=$PWD
echo "*****" | sudo -S updatedb
filist=~/Movies/files.txt
if [ "$1" = "-purge" ]; then
rm -r ~/Movies/TV/*
else
echo
fi
mkdir ~/Movies/HD
mkdir ~/Movies/SD
mkdir ~/Movies/3D
mkdir ~/Movies/All
sh ~/Scripts/relink.hd
sh ~/Scripts/relink.sd
sh ~/Scripts/relink.3d
cd /mnt/Storage/TV/ && find . -type d -exec mkdir -p ~/Movies/TV/{} \;
cd /mnt/Movies/TV/ && find . -type d -exec mkdir -p ~/Movies/TV/{} \;
cd /mnt/MoviesB/TV/ && find . -type d -exec mkdir -p ~/Movies/TV/{} \;
cd /mnt/MoviesA/TV/ && find . -type d -exec mkdir -p ~/Movies/TV/{} \;

locate /mnt/MoviesB/TV/*.mkv>$filist
locate /mnt/MoviesB/TV/*.avi>>$filist
locate /mnt/MoviesB/TV/*.mp4>>$filist
locate /mnt/Storage/TV/*.mkv>>$filist
locate /mnt/Storage/TV/*.avi>>$filist
locate /mnt/Storage/TV/*.mp4>>$filist
locate /mnt/Movies/TV/*.mkv>>$filist
locate /mnt/Movies/TV/*.avi>>$filist
locate /mnt/Movies/TV/*.mp4>>$filist
locate /mnt/MoviesA/TV/*.mkv>>$filist
locate /mnt/MoviesA/TV/*.avi>>$filist
locate /mnt/MoviesA/TV/*.mp4>>$filist

while read file
do
path=${file##*/mnt/Movies/TV/}
path=${path##*/mnt/Storage/TV/}
path=${path##*/mnt/MoviesB/TV/}
path=${path##*/mnt/MoviesA/TV/}
ln -s "$file" ~/Movies/TV/"$path"
echo $file
echo $path
done < $filist
rm ~/Movies/files.txt
rm ~/Movies/All/*
cp -P ~/Movies/SD/* ~/Movies/All
cp -P ~/Movies/HD/* ~/Movies/All
cp -P ~/Movies/3D/* ~/Movies/All
rm ~/Movies/All/"*"
cd $tree
date  >> /home/adam/Scripts/relinks.log

and here is a sample of one of the called scripts, I wont put them all up, they are all just the same thing with different folder locations.
Code:
stdir=$PWD
echo $stdir
cd ~/Movies/HD
# rm *
ln -s /mnt/Movies/HD/* ~/Movies/HD/
ln -s /mnt/Storage/HD/* ~/Movies/HD/
ln -s /mnt/MoviesA/HD/* ~/Movies/HD/
ln -s /mnt/MoviesB/HD/* ~/Movies/HD/
cd ~/Movies/HD
rm "*"
ls
cd $stdir

Now I'm almost positive that someone will come here and tell me that you could do the same thing with only 2 lines of code, and i'm sure you can, but I dont care, because I wrote this myself, and that makes it my favourite way of doing this task.

Have fun, and I cant wait to see what some of you have come up with (Or at least what you're willing to share wink.gif )
post #2 of 305
You should add
Code:
#!/bin/sh
to the top of your script and then set the executable permission bit (chmod +x /path/to/script) and then you can run it just by calling the file (without manually calling sh / whatever)
post #3 of 305
Thread Starter 
I know i need to tidy them up a bit, but they are all chmod +x, and I really should give myself permission to use updatedb without having to echo my pw to sudo as well, I'm just glad that I remembered to blank it out before posting it lol
post #4 of 305
Quote:
Originally Posted by bilbs84 View Post

I know i need to tidy them up a bit, but they are all chmod +x, and I really should give myself permission to use updatedb without having to echo my pw to sudo as well, I'm just glad that I remembered to blank it out before posting it lol

oh wow, missed that bit. Yeah that's a massive no no.

You can also update your sudoers (visudo) to allow you to run updatedb without a password, if it genuinely requires root permissions to run.
post #5 of 305
Your script is unusable for everyone but you, this is because you haven't generalized the code.
post #6 of 305
Found idea for this on Mint forums. Ultimate in laziness which is why I love it.
Script Here. (Click to show)
Code:
#!/bin/bash
#Script Name : myscriptmaker
#Purpose : create script template
#Original Idea : mint forums
#Author : Tadaen Sylvermane
#Date : 2014-4-9
#Version : 1.0

## variables ##

NOW=$(date +"%Y-%m-%d  %H%M hrs")

##### begin script #####

if [ ! -e $1 ] ; then

## create script ##

        echo "#!/bin/bash
#Script Name : $1
#Purpose :
#Author : Tadaen Sylvermane
#Date : $NOW
#Version : 1.0

## variables ##

##### begin script #####

##### end script #####" > $1

## set script executable ##

        chmod 744 $1

## edit script ##

        nano $1

## close out ##

        echo "Script created and ready for use!!"
fi

##### end script #####
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
 
Micromachine
(8 items)
 
 
CPUMotherboardGraphicsRAM
i7 4500u Inspiron 15 7000 Integrated 8gb 
Hard DriveOSMouse
120gb Samsung EVO SSD Debian Logitech m705 
CPUMotherboardRAMHard Drive
AMD 5350 Kabini AsRock AM1H-ITX 8gb Gskill Ripjaws (2x4) Samsung 120 Evo 
Hard DriveHard DriveOSCase
WD 1tb 2.5 WD 2tb USB 3.0 Ubuntu Server 16.04 Antec ISK 
  hide details  
Reply
post #7 of 305
Here's one of my likely useless scripts biggrin.gif
Code:
#!/bin/bash
#Use this to display CPU and GPU info
#chmod +x first

echo "CPU: "; echo " "; cat /proc/cpuinfo ; echo " ";
echo "GPU: "; echo " "; lspci | grep VGA ; echo " ";
echo "RAM: "; free -m /n
echo "Drives: "; echo " "; df -h
     
CPUGraphicsRAMHard Drive
Intel Core m3-6Y30 Intel HD515 8GB 1866DDR3L Micron M600 MTFDDAV256MBF M.2, 256 GB 
CoolingOSOSMonitor
Fanless Win10 Home x64 Kubuntu 16.04 (requires Linux kernel 4.5/4.6) 13.3 inch 16:9, 1920x1080 pixel, AU Optronics A... 
CPUMotherboardGraphicsRAM
AthlonIIX4 640 3.62GHz (250x14.5) 2.5GHz NB Asus M4A785TD-M EVO MSI GTX275 (Stock 666) 8GBs of GSkill 1600 
RAMHard DriveHard DriveHard Drive
4GBs of Adata 1333 Kingston HyperX 3k 120GB WD Caviar Black 500GB Hitachi Deskstar 1TB 
Optical DriveCoolingOSOS
LG 8X BDR (WHL08S20) Cooler Master Hyper 212+ Kubuntu x64 Windows 7 x64 
OSMonitorPowerCase
Bodhi Linux x64 Acer G215H (1920x1080) Seasonic 520 HAF912 
CPUMotherboardGraphicsRAM
N450 1.8GHz AC and 1.66GHz batt ASUS proprietary for 1001P GMA3150 (can play bluray now!?) 1GB DDR2 
Hard DriveOptical DriveOSOS
160GB LGLHDLBDRE32X Bodhi Linux Fedora LXDE 
OSOSMonitorKeyboard
Kubuntu SLAX 1280x600 + Dell 15inch Excellent! 
PowerCase
6 cells=6-12hrs and a charger 1001P MU17 Black 
  hide details  
Reply
     
CPUGraphicsRAMHard Drive
Intel Core m3-6Y30 Intel HD515 8GB 1866DDR3L Micron M600 MTFDDAV256MBF M.2, 256 GB 
CoolingOSOSMonitor
Fanless Win10 Home x64 Kubuntu 16.04 (requires Linux kernel 4.5/4.6) 13.3 inch 16:9, 1920x1080 pixel, AU Optronics A... 
CPUMotherboardGraphicsRAM
AthlonIIX4 640 3.62GHz (250x14.5) 2.5GHz NB Asus M4A785TD-M EVO MSI GTX275 (Stock 666) 8GBs of GSkill 1600 
RAMHard DriveHard DriveHard Drive
4GBs of Adata 1333 Kingston HyperX 3k 120GB WD Caviar Black 500GB Hitachi Deskstar 1TB 
Optical DriveCoolingOSOS
LG 8X BDR (WHL08S20) Cooler Master Hyper 212+ Kubuntu x64 Windows 7 x64 
OSMonitorPowerCase
Bodhi Linux x64 Acer G215H (1920x1080) Seasonic 520 HAF912 
CPUMotherboardGraphicsRAM
N450 1.8GHz AC and 1.66GHz batt ASUS proprietary for 1001P GMA3150 (can play bluray now!?) 1GB DDR2 
Hard DriveOptical DriveOSOS
160GB LGLHDLBDRE32X Bodhi Linux Fedora LXDE 
OSOSMonitorKeyboard
Kubuntu SLAX 1280x600 + Dell 15inch Excellent! 
PowerCase
6 cells=6-12hrs and a charger 1001P MU17 Black 
  hide details  
Reply
post #8 of 305
Thread Starter 
Tadaen, I just used your script to make Rookie1337's script lol, I like that one, thank you for sharing.
post #9 of 305
Quote:
Originally Posted by Rookie1337 View Post

Here's one of my likely useless scripts biggrin.gif
Code:
#!/bin/bash
#Use this to display CPU and GPU info
#chmod +x first

echo "CPU: "; echo " "; cat /proc/cpuinfo ; echo " ";
echo "GPU: "; echo " "; lspci | grep VGA ; echo " ";
echo "RAM: "; free -m /n
echo "Drives: "; echo " "; df -h

Cheeky one-liner:
Code:
echo -e "CPU:\n$(cat /proc/cpuinfo)\n\n\nGPU\n$(lspci|grep VGA)\n\n\nRAM:\n$(free -m)\n\n\nDrives:\n$(df -h)"
post #10 of 305
Quote:
Originally Posted by Plan9 View Post

Cheeky one-liner:
Code:
echo -e "CPU:\n$(cat /proc/cpuinfo)\n\n\nGPU\n$(lspci|grep VGA)\n\n\nRAM:\n$(free -m)\n\n\nDrives:\n$(df -h)"

Damn. Now I can't demand credit because mine isn't as good. Why must you upstage? JK. That's probably a far better way to do it. Thanks for the demo.
     
CPUGraphicsRAMHard Drive
Intel Core m3-6Y30 Intel HD515 8GB 1866DDR3L Micron M600 MTFDDAV256MBF M.2, 256 GB 
CoolingOSOSMonitor
Fanless Win10 Home x64 Kubuntu 16.04 (requires Linux kernel 4.5/4.6) 13.3 inch 16:9, 1920x1080 pixel, AU Optronics A... 
CPUMotherboardGraphicsRAM
AthlonIIX4 640 3.62GHz (250x14.5) 2.5GHz NB Asus M4A785TD-M EVO MSI GTX275 (Stock 666) 8GBs of GSkill 1600 
RAMHard DriveHard DriveHard Drive
4GBs of Adata 1333 Kingston HyperX 3k 120GB WD Caviar Black 500GB Hitachi Deskstar 1TB 
Optical DriveCoolingOSOS
LG 8X BDR (WHL08S20) Cooler Master Hyper 212+ Kubuntu x64 Windows 7 x64 
OSMonitorPowerCase
Bodhi Linux x64 Acer G215H (1920x1080) Seasonic 520 HAF912 
CPUMotherboardGraphicsRAM
N450 1.8GHz AC and 1.66GHz batt ASUS proprietary for 1001P GMA3150 (can play bluray now!?) 1GB DDR2 
Hard DriveOptical DriveOSOS
160GB LGLHDLBDRE32X Bodhi Linux Fedora LXDE 
OSOSMonitorKeyboard
Kubuntu SLAX 1280x600 + Dell 15inch Excellent! 
PowerCase
6 cells=6-12hrs and a charger 1001P MU17 Black 
  hide details  
Reply
     
CPUGraphicsRAMHard Drive
Intel Core m3-6Y30 Intel HD515 8GB 1866DDR3L Micron M600 MTFDDAV256MBF M.2, 256 GB 
CoolingOSOSMonitor
Fanless Win10 Home x64 Kubuntu 16.04 (requires Linux kernel 4.5/4.6) 13.3 inch 16:9, 1920x1080 pixel, AU Optronics A... 
CPUMotherboardGraphicsRAM
AthlonIIX4 640 3.62GHz (250x14.5) 2.5GHz NB Asus M4A785TD-M EVO MSI GTX275 (Stock 666) 8GBs of GSkill 1600 
RAMHard DriveHard DriveHard Drive
4GBs of Adata 1333 Kingston HyperX 3k 120GB WD Caviar Black 500GB Hitachi Deskstar 1TB 
Optical DriveCoolingOSOS
LG 8X BDR (WHL08S20) Cooler Master Hyper 212+ Kubuntu x64 Windows 7 x64 
OSMonitorPowerCase
Bodhi Linux x64 Acer G215H (1920x1080) Seasonic 520 HAF912 
CPUMotherboardGraphicsRAM
N450 1.8GHz AC and 1.66GHz batt ASUS proprietary for 1001P GMA3150 (can play bluray now!?) 1GB DDR2 
Hard DriveOptical DriveOSOS
160GB LGLHDLBDRE32X Bodhi Linux Fedora LXDE 
OSOSMonitorKeyboard
Kubuntu SLAX 1280x600 + Dell 15inch Excellent! 
PowerCase
6 cells=6-12hrs and a charger 1001P MU17 Black 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › Share your Scripts