Jump to content

Please audit my script and I need a little help


cirkator

Recommended Posts

Hi all,

 

[glow=red,2,300]PLEASE DONT USE THIS SCRIPT YET ON YOUR PRODUCTION SERVER!!!

ALTOUGH IT IS WORKING FINE FOR ME, I WOULD LIKE TO HAVE SOMEONE WITH REAL CODING SKILLS FIRST LOOK OVER MY CODE[/glow]

This is only my second script and i am not a programmer by trade so please be kind :)

 

 

I have written this little script that reads the content of each of your servers disks and outputs it to a disk*.txt file.

This can prove handy, when two disks would die and you dont know what specific content is on each disk.

 

The script is utilizing another shell script written by Tony Lauro that displays the content in a tree view and colors the filenames according to their group. (E.g. media files are orange, pictures purple and so on)

 

My script is working, but I would prefer if some of you coding savy people could look over my script and give me feedback please.

 

aCZpT7e.png

 

 

I already have one question. There are some paths and variables that are user defineable. Normally all those user defineable values are at the top of a script, so it is user friendly.

 

But on line 25, in disk_content.sh i want to define the outputpath where all the disk*.txt files are saved. The script creates a folder with the current date and then it saves all the disk*.txt files into that folder. So before i can create the $DATE folder i have to create the value for $DATE. But if $DATE needs to already be created, i can not put the outputpath variable on top of the script so users can change it easily.

I hope I made myself clear, englisch is not my native language.

So, what can i do about that? I guess i could use "jump" commands, altough i am not sure if there is an easier solution to my problem.

 

I have some other ideas for this script in the future (zip the files, delete txt files older than x days). Looking forward to finally giving something back to this awesome community :)

 

 

 

Both scripts are located at github: https://github.com/cirkator/DiskContent

You will need to download both scripts and chmod +x them.

The standard path to put the scripts and write the disk*.txt files is at "/boot/scripts/" but you can change these values (TREE_PATH & OUTPUT_PATH)

It will create, as default, the disk*.txt files into this path: /boot/scripts/DiskContent/17.06.2015/disk1.txt etc.

 

Feedback and critisicm is very welcome!

 

Link to comment

thanks for sharing it with us

 

just to let you know, to do this manually, you can do this

 

tree /mnt/disk2 -d > disk2.txt
tree /mnt/disk3 -d > disk3.txt
.
.
.
.,,,and so on...

 

I know it's a hassle specially if you have a lot of drives, but hey, it won't hurt to do it once every 6 months...

Link to comment

thanks for sharing it with us

 

just to let you know, to do this manually, you can do this

 

tree /mnt/disk2 -d > disk2.txt
tree /mnt/disk3 -d > disk3.txt
.
.
.
.,,,and so on...

 

I know it's a hassle specially if you have a lot of drives, but hey, it won't hurt to do it once every 6 months...

You can do it in a single command whatever number of disks you have as

tree -d /mnt/disk* > disktree.txt 

Link to comment

So i have something I use but its based in perl and very specific to the way I work.

 

Things I have learned:

 

forget pretty tree think machine parsable/grep i.e. ls

you want to list perms and filesizes because its amazing how often you can recover from things like a bad rename just by filesize

you never want to > you want to keep every version for diffs... think epoch date in filename

I put a small file in the root of each disks and name that file so represent the disk.... lets say disk37.id. The way you do it is bad because /mnt/disk2 can change i.e. disk number changes

 

I commend your going public with this. Regardless of where you end up you will learn a lot

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...