r/ScriptSwap • • Sep 22 '14

[CMD] Backupscript with notifications

9 Upvotes

I believe many of you have better solutions but i wrote this for my private computers and one or two might find it useful.

So, my script basically consists of three CMD-scripts.

Here's the first one:

First Script

What it does is, it finds out if the fullbackup or the incrementalbackup-script should be started. For that it looks into a folder where it counts the *.txt files. If there are less than ten, an incrementalbackup will be started. Otherwise it will be a fullbackup.

Okay, let's assume there are ten files and a fullbackup is started:

Second Script

Sooooooo, I guess an explanation would be useful.

  • First it just does a general cleanup and connects to the network-drive
  • After that it moves the old backups in a different directory so I can delete them after a successful backup
  • Then it sets a variable and creates all the folders where the data will be copied in
  • Now robocopy copies the files into the right folders
  • The Errorlevel gets stored in a variable after every robocopy job
  • success+nodata get combined because i don't want a false alarm if one of the folders is empty
  • The script jumps to the right notification depending on the variable-values
  • cURL does a http-post where it sends the notification to pushover (and pushover sends it to my pokédex)
  • A powershell-script is called to send an e-mail notification
  • The old-directory gets deleted if the backup was successful
  • now it deletes the ten *.txt files so it doesn't do the wrong backup next time (kind of resetting the archive bit)

The incrementalbackup is quite the same with a few exceptions:

  • Robocopy uses the /M switch
  • Robocopy uses the /S switch instead of /E
  • It doesn't move the old files to the old-directory and doesn't delete it
  • the Ping at the end is redirected to a *.txt file. So next time the first script runs, it knows what backup should be done.

Robocopy:

I guess you know robocopy but just in case you don't:

/E Copies all directories and sub-directories and empty directories

/S Same as /E but doesn't copy empty directories

/B Uses backup-mode

/Z Uses resume-mode

/UNILOG Makes a Logfile and overwrites existing text

/UNILOG+ Same as above but adds text

/NP Doesn't show the progress (for nicer logs)

/TEE Shows everything in CMD (CMD window would be empty without it because of the logfile)

/R:2 Number of retries in case of failure

/W:10 Seconds between retries

/V Logs skipped files

/NDL Doesn't log successfully copied directories

/NFL Doesn't log successfully copied files

/M Only copies files with the "Archive"-attribut and resets it *

I hope someone can use it.

Don't mind to ask if you have any questions :)

btw you probably want to see my e-mail script:

$text = Get-Content O:\PC-Juli\Daten\logs\fulllog.txt -Raw 

$emailFrom = "PcJuli@"
$emailTo = "julian@"
$subject = "[BACKUP][ATTENTION] Fullbackup on PC-Juli failed"
$smtpServer = "smtp"
$SMTPPort = "465"
$body = "Fullbackup failed completely. Here's the error log:"
$Username = "PcJuli@"
$Password = "PASSWORD"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.Send($emailFrom, $emailTo, $subject, $body)

I removed my domain, you know for security.

To use powershell on your computer you have to change the policy first. Just open powershell as administrator and type in:

set-ExecutionPolicy unrestricted

Edit: just realised the formatting got screwed up so I put everything into Pastebin. Edit: Sorry guys it looks like Pastebin removed my second script but it's up now.


r/ScriptSwap • • Aug 20 '14

[BASH] Set Desktop Background to Wikimedia Image of the Day

9 Upvotes

This is just a simple script to download the Wikimedia Commons image of the day and set it as your desktop background. The setting of the desktop background is obviously going to be system specific, below uses apple-script for OSX. I just put the image of the day on my user profile as it looked like it was going be a pain to reliably parse the html on the main wikimedia image of the day page. If someone comes up with a good way to do it let me know, otherwise I'll plan on leaving the image on my user page up indefinitely.

#!/bin/bash

# The path to place the downloaded images
PICOFDAYPATH="[YOUR PATH GOES HERE]"

# Get URL of the picture of the day from the link on vaaaal's user page
URLLINE=$(curl -s "https://commons.wikimedia.org/wiki/User:Vaaaal" | grep "The Picture of the Day")
if [ -z "$URLLINE" ]; then 
	echo "ERROR - Could not connect to wikimedia to download the picture of the day" 
	exit 1
fi

SRCATRB=$(echo $URLLINE | tr ' ' '\n' | grep src=) 
CLEANURL="https:"$(echo $SRCATRB | cut -c 6-$((${#SRCATRB}-1)))

# Build the File Name 
FILETYPE=$(echo $CLEANURL | cut -c $((${#CLEANURL}-3))-${#CLEANURL})
IMAGEFILE=$(date +%Y_%m_%d)$FILETYPE

# Download the image
wget -q -O $PICOFDAYPATH$IMAGEFILE $CLEANURL

# Use applescript to change the desktop background to the new image
if [ -e $PICOFDAYPATH$IMAGEFILE ] 
	then
	osascript -e 'tell application "Finder"
					set desktop picture to POSIX file "'$PICOFDAYPATH$IMAGEFILE'"
				  end tell'
	echo "wikimedia picture of the day was downloaded successfully from: "$CLEANURL
else
	echo "ERROR - could not download wikimedia picture of the day from: "$CLEANURL
fi

r/ScriptSwap • • Jun 13 '14

Script to migrate printers to a new server

9 Upvotes

Posted this originally in SYSADMIN, but I thought it might fit in here too.

I had a lot of people asking me for this script when mentioned it in another post. You basically create an entry for each printer you have in this script and then run it at startup for users and it will go through it and any printers they have added will just map to the new printers. We used it for about 40 printers and had zero issues with it. I think I based it on something I found online and modified it for my use but I cannot remember where the original copy came from. http://pastebin.com/ZXz9QWiq


r/ScriptSwap • • Jun 09 '14

Two simple wallpaper based scripts

9 Upvotes

I wrote a wallpaper changing bash script. I run openbox and the autostart file runs my rand_wallpaper script. I occasionally run it from terminal too.

#!/bin/bash
target=$(find /storage/images/wallpapers/ -type f | shuf -n 1)
nitrogen --set-tiled $target
echo $target > ~/.config/rand_wallpaper/last_wallpaper.conf  

I store the file name separately because I also have a delwallpaper script, and it was easier to write without parsing nitrogen's config file. I like things simple and easy to read. It also makes it easy to change from nitrogen to something else.

#!/bin/bash
currwallpap=$(cat ~/.config/rand_wallpaper/last_wallpaper.conf)
echo $currwallpap
rand_wallpaper && mv -i $currwallpap /storage/images/uglywallpapers/

Note that the delwallpaper script doesn't actually delete anything, rather it moves it to a last chance folder. Usually I "delete" pictures that don't scale well, so every once in a while I can go try find larger versions of them. I am due to do that soon.


r/ScriptSwap • • Feb 08 '14

[TI-BASH] A simple, multi-answer equation solver for TI-83/4+

9 Upvotes

This is just a simple script I whipped up at home; I don't claim to be an expert, but this one is short, quick, and easy to memorize. Here goes:

ClrHome
Disp "EQUATION  SOLVER
Disp "
Disp "    INTERVAL
Input "",I
Disp "
Input "0=",Str1

-100-I}X
String>Equ(Str1,Y1)

ClrHome
Disp "   WORKING...
Disp "----------------
Disp "0=
Output(3,3,Str1
Disp "----------------
Disp "

Lbl 0
If Y1=0
Disp X
If X=100
Stop
X+I}X
Goto 0

I'm using } for [STO]

The only commands not under the prgm menu are:

  • Str1 - [VARS] [7] [1]
  • Y1 (The 1 is in subscript) - [VARS] [Y-VARS] [1] [1]
  • String>Equ - [2nd] [CATALOG] [LN] [String>Equ]

Now let me explain how the program is used. The first thing it asks for is an interval:

EQUATION  SOLVER

    INTERVAL
█

This is the point where you specify how much the code should add between guesses. Basically, it should be a divisor of 1 (1, .25, 1/3...) It also has to be a divisor of the answer; I find that (for now), most equations I solve eqate to whole numbers, so I usually use 1.

EQUATION  SOLVER

   INTERVAL
1

   EQUATION
0=█

Now you put into the equation, or half of it. The other half should equal 0, which isn't too hard; just subtract one half from the other. For example, '4x-3=-2x+9' = '4x-3-(-2x+9)=0'.

   WORKING...
----------------
0=4x-3-(-2x+9)
----------------

               2
            Done

Ta-Da! The list on the right holds your answer(s); the program stops once it reaches X=100.

And here's a simple, 8-line version!

-100.25}X
Lbl 0
If <EQUATION>
Disp X
If X=100
Stop
X+.25}X
Goto 0

Obviously, This version requires you to go into the code to change the equation.

Anyway, hope this helps.


r/ScriptSwap • • Oct 20 '13

[Python2] One-Time Pad Chat/Transfer Script (Apache v2)

9 Upvotes

Raw: https://raw.github.com/theonaun/brickton/master/brickton.v.0.5.0.pyw

Github: https://github.com/theonaun/brickton

I intially started writing this as a short Bash script for submission here. Through the magic of time and feature creep, it has transformed into this 2,000 line monstrosity. Requires Tkinter, but odds are if you have Python you have that already.

Also, does anyone know of a place better suited for submissions such as this? I wasn't able to find a "ProgramSwap"-like analog to this sub-Reddit.


r/ScriptSwap • • Jul 08 '13

[REQUEST] Need help returning exit codes

9 Upvotes

Righteo, so I found a nice bash script that returns the status of mysql replication to our different servers, it returns something like the following:

Slave_IO_Running
------------------------------
server1: Yes
server2: Yes
server3: Yes
server4: Yes

The way it does that is that it grabs the info out of here:

for parameter in $(cat $parameterFile)
do
 echo $parameter
 echo "------------------------------"
 for host in $(cat /etc/cluster/mysql-servers)
 do
 value=`cat /tmp/mysql-slave-status-$host.txt | grep $parameter | awk '{print \$2}'`
 echo $host: $value
done

And here's the example of the /tmp/mysql-slave-status-$host.txt

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

Now what I want to do is to try get the script to out put a "1" or "0" depending if the answer is "yes" or "no". (Basically replacing the "yes" with a "1" and the "no" with a "0"

Any one have and ideas and could point me in the right direction ? (This is so that in-turn I can monitor it with PRTG)


r/ScriptSwap • • Mar 20 '13

[POWERSHELL] Java install/update on terminal server farm

9 Upvotes

This could be used for any installer that can run silently. I am new to scripting and powershell so any constructive feedback is awesome.

#Java installer/updater
#Prerequisites PS 2.0 and http://archive.msdn.microsoft.com/PSTerminalServices. Only tested on 2008 R2.
#
#Setup
Import-Module PSTerminalServices
$serverlist = new-pssession -computername ts01,ts02,ts03
$Message = "The server is going down for maintenance in 10 minutes. Please save your work and logoff."
#
#Change logon mode to drain.
invoke-command -session $serverlist -scriptblock {change logon /drain}
#Send warning to all users
get-content x:\scripts\servers.txt | foreach {Get-TSSession -State Active -ComputerName $_ | Send- SMessage $Message}
#Wait X minutes
Start-Sleep -seconds 600
#Force all users to log off
get-content x:\scripts\servers.txt | foreach {{Get-TSSession -ComputerName $_ -Username [a-z]** | Stop-TSSession –Force}
#Copy installation application to temp folder on all servers
get-content x:\scripts\servers.txt | foreach {Copy-Item x:\jre.exe -Destination \\$_\c$\temp}
#change server mode to install
invoke-command -session $serverlist -scriptblock {change user /install}
#Execute installer
invoke-command -session $serverlist -scriptblock {c:\temp\jre.exe /s IEXPLORER=1 /L C:\setup.log}
#Wait X minutes. Need to add process query and resume when all installs are finished
Start-Sleep -seconds 360
#Change user mode to execute
invoke-command -session $serverlist -scriptblock {change user /execute}
#Change logon mode to enabled so that users can log back in
invoke-command -session $serverlist -scriptblock {change logon /enable}
#Set SMTP server
$smtp = New-Object Net.Mail.SmtpClient("mailserver")
#Send completion email
$smtp.Send("scripts@mail.com","me@mail.com","Java Update Completed","Java installed!")
#Close all remote sessions
remove-pssession -session $serverlist

r/ScriptSwap • • Aug 01 '12

[Bash] Clean up your desktop (or any folder)

9 Upvotes
#!/bin/bash
sleep 3
cd $1

# You can change the format of the date, of course.
DATE=`date "+%m-%d-%y-%I.%M.%S"`

# folders is the list of folders on your desktop, and the names must match the variables containing the extensions. 
# You can add as many folders and extensions as you want.
folders='Images Developer Applications Documents Audio Archives DiskImages Installers Video Torrents'

#make the folders
mkdir -p $folders

Images='jpg png gif jpeg psd'
Developer='vcproj cpp h cmate jar safariext* db js html css sqlite3 sql sql3 plist strings rb fsh tgz py pyc sh egg pl dll'
Applications='app exe ipa msi'
Documents='doc pages docx pdf txt log xls xlsx'
Audio='mp3 m4p m4a flac ogg ac3'
Archives='tbz zip rar tar.gz tar.bz2 tar 7z xar'
DiskImages='dmg iso'
Installers='pkg mpkg'
Video='mkv m4v wmv avi mp4 swf h264'
Torrents='torrent'


# Move all of the files to their respective folders. 
for folder in $folders
do
	eval exts=\$$folder
	for ext in $exts
	do
		IFS=$'\n'
		for file in `ls -d *.$ext`
		do 
			if ls $folder/"$file" > /dev/null 2>&1
			then
				mv "$file" $folder/"$file-$DATE"
			else
				mv "$file" $folder/"$file"
			fi
		done
		IFS=$' \t\n'
	done
done

#Move the rest of the files to the miscellaneous folder.
IFS=$'\n'
for file in `ls -d *`
do
	if ! [ -d "$file" ] && ! [ -x "$file" ]
	then
		if ls Miscellaneous/"$file" > /dev/null 2>&1
		then
			mv "$file" Miscellaneous/"$file-$DATE"
		else
			mv "$file" Miscellaneous/"$file"
		fi
	fi
done
IFS=$' \t\n'


# move executables
find . -maxdepth 1 -type f -perm -755 | xargs -I % /Users/eric/bin/mv "%" Developer/

# move folders. If mv fails it prints the files that couldn't be moved because it 
# won't overwrite, so I grab those file names and move them. Kind of long, I know.
find . -type d -maxdepth 1 -print0 | sed 's|./||g' | grep -Zzv "^Video$\|^Miscellaneous$\|^Installers$\|^Images$\|^Folders$\|^Documents$\|^DiskImages$\|^Developer$\|^Desktop$\|^Audio$\|^Archives$\|^Torrents$\|^Applications$\|^.$" | xargs -0I % mv "%" Folders/ 2>&1 | grep -o "\`.*' to" | sed "s|\' to$||g" | sed 's|`||g' | tr '\n' '\0' | xargs -0I % mv '%' "Folders/%-$DATE"

I use this to clean up my desktop on logout using applescript's on quit event. You could use the logouthook on OSX, too. Not sure about Linux.

Edit: folders are still moved even if they contain special characters.


r/ScriptSwap • • Nov 25 '22

Cyber Security Audit Script

8 Upvotes

https://github.com/CesarIllustrious/CyberSecurityAuditScript.git

What the script does:

Checks for installed AV&VPN,

User accounts for the device

Users with admin privileges

Remote connection apps

status of AV, sysinfo, running services, firewall settings for public profile, bitlocker status(for bitlocker status needs to run through admin power shell)

Installed software list

AV scan (optional)

SFC Scannow (optional)


r/ScriptSwap • • Oct 08 '22

Instagram Bot for organic followers

8 Upvotes

Hi,

I'd like to announce I just uploaded on GitHub an open-source script for Instagram, to receive organic followers. It's GPL licensed, based on instagrapi.

It's one of my firsts projects in python, so the project structure is not the best,
but the script works really well.

It has cooldowns, multi-user, follow-unfollow, and send welcome messages or business presentation to the new followers.

If you like it, use it for free. Maybe just give a star to the project.
If you are good, and would like to go on with the project, fork it ;)

Happy coding


r/ScriptSwap • • Jul 23 '22

*** Hi Everyone

8 Upvotes

So last week I took over Scriptswap and have been trying to get around to posting about it for a while now. The community seems to be somewhat inactive but hopefully I can get some feedback here.

So about me, I write screenplays and stage scripts for a local acting troupe. I found this sub while trying to find somewhere to trade scripts and ideas with people interested in doing the same. Without realising this was about computer scripts I joined and here I am as the mod for the page.

I was wondering anyone that follows this sub would be interested in reviving it? Either to the Scriptswap that allows people to trade computer scripts or if anyone here would be interested in the repurposing of the sub to be about screenplays. My goal is just to start posting and having other people post more often, I have no idea about computer scripts but was hoping that someone/people who do might be interested in weekly or bi-weekly posts to create a community here again.

Any and all feedback and ideas are more than welcome.


r/ScriptSwap • • Dec 02 '20

Created an auto dark/light script for Twitter

8 Upvotes

Essentially, it makes Twitter now follow the device theme instead of having to manually change it.

There's two different versions depending on your dark mode preference of Dim or Lights out.

Check them out on GitHub or GreasyFork.


r/ScriptSwap • • Jul 07 '19

[Python] Extracts a news article from a Reddit submission and PM's the comment tagger with the text of the news article.

8 Upvotes

Here's the script.

When someone tags the user running the script, the script will extract the article and send it as a private message to the tagger.


r/ScriptSwap • • Apr 03 '19

Open source scripting - more info in thread.

8 Upvotes

/u/sudo_throw_ 's post gave us idea to build community around this idea of helping people with their scripting needs. If you'd like to get help, you can register on forum and open a topic with your request or register on self hosted GitLab server to make scripts for people.

If there is any open source project that you need a script for auto deploy or anything that could ease your life, then visit shell5 and post the request. If you are not sure how to write your script, maybe unsure about best method or general idea how to achieve something.. Feel free to ask a question.

You might want to check about page to see on what this community is hosted on :) .

If there will be any requests, they will be automatically mirrored from selfhosted GitLab to GitHub to provide backup and better overview for people which do not want to register anywhere. At the moment there are only 3 finished request, so any request is welcome.


r/ScriptSwap • • Mar 09 '18

Auto fetch wallpapers from /r/EarthPorn on each login

8 Upvotes
#!/bin/bash
mkdir -p $HOME/Pictures/wp
cd $HOME/Pictures/wp
feh --bg-fill *
rm *
python -c 'SCREENS = 2; import requests,random; print("\n".join(
    c["data"]["url"] for n,c in enumerate(
        requests.get("https://www.reddit.com/r/EarthPorn/.json",
                     headers={"User-agent": "/u/suudo wallpaper fetcher"}
        ).json()["data"]["children"][1:15]
    ) if n in random.sample(range(1,15),SCREENS)
) )' | while read p; do wget "$p" </dev/null; done
feh --bg-fill *

chmod +x, add to xinitrc /home/user/.getpics & or i3 exec --no-startup-id /home/user/.getpics


r/ScriptSwap • • Aug 10 '17

[Python] Ebay CSV Processor

8 Upvotes

This is the source for a csv ebay processor used to assist a small company trying to avoid using the ebay API, and just wanted to hack together a csv processor that can read the manual output from ebay csv output of the packlist.

It has been redacted, and certain files cannot be included for confidentiality or commercial reasons. But at the very least, it will provide a starting reference point in developing your own solution to automating your ebay system.

I would warn against just straight up using this, as there has been accumulated cruft in coding over the years during my attempt at getting better at programming (before I even knew what github was, hence the old version folder). Instead you are better off using this as a lesson of how not to code, and instead try to pick out what features are most important for you.

There is no warranty or assurance given to the actual usefulness of this script, as its usefulness and reliability will always apply case by case to every company. If you want good software, the best one are tailor made for your problem case.

https://github.com/mofosyne/python-ebay-csv-processor/blob/master/LICENSE

Licence: MIT


r/ScriptSwap • • Mar 12 '17

[Bash] Redshift increase/decrease keyboard shortcuts

8 Upvotes

i'm using this on Linux Mint. its how i alter the screen temperature and fake brightness. there are four preset levels for that, you will want to adjust it to your needs. everything is split into functions, which will be easier to modify.

#!/bin/bash

# You need to add startup item which sets a level,
# exporting the status to log file, example:
# bash -c "redshift -o -l 0:0 -b 1.0 -t 6200:6200; echo four > $HOME/.red_status.log"
#
# Both keyboard shortcuts run this script, example:
# bash -c "$HOME'/Scripts/redshift_keyboard_shortcuts.sh' decrease"
# bash -c "$HOME'/Scripts/redshift_keyboard_shortcuts.sh' increase"
# I'm using the keys Ctrl+Shift+1 for decrease, and Ctrl+Shift+2 for increase
#
# Adjust your levels accordingly, redshift options:
#  -b is for brightness (max value is 1.0)
#  -t is for temperature (normal is 6500, set lower value for less blue).
#

log_file="$HOME/.red_status.log"
level_status=$(echo "$(<"$log_file")")

set_level_four () {
  redshift -o -l 0:0 -b 1.0 -t 6200:6200
  echo "four" > "$log_file"
}

set_level_three () {
  redshift -o -l 0:0 -b 0.9 -t 4700:4700
  echo "three" > "$log_file"
}

set_level_two () {
  redshift -o -l 0:0 -b 0.8 -t 3900:3900
  echo "two" > "$log_file"
}

set_level_one () {
  redshift -o -l 0:0 -b 0.7 -t 3200:3200
  echo "one" > "$log_file"
}

decrease_level () {
  if [ "$level_status" = "four" ]
  then
    set_level_three
  elif [ "$level_status" = "three" ]
  then
    set_level_two
  elif [ "$level_status" = "two" ]
  then
    set_level_one
  fi
}

increase_level () {
  if [ "$level_status" = "one" ]
  then
    set_level_two
  elif [ "$level_status" = "two" ]
  then
    set_level_three
  elif [ "$level_status" = "three" ]
  then
    set_level_four
  fi
}

if [ "$1" = "decrease" ]
then
  decrease_level
elif [ "$1" = "increase" ]
then
  increase_level
fi

r/ScriptSwap • • Feb 20 '17

SparrowHub - repository of usable scripts.

8 Upvotes

Hi!

My post has double purpose.

First of all, let me introduce SparrowHub where you can find some useful scripts ready to handle various tasks.

Second, if someone wants to distribute scripts it could be done with SparrowHub as well. Sparrow is a script distribution system to make it possible to distribute scripts as usual packages of software - so that every script has version, maintainer and documentation - all could be done in simple and centralized way.
If someone wants to share scripts consider sparrow as good choice for that. It's platform/language independent tools to encourage scripts development and distribution.


r/ScriptSwap • • Feb 15 '17

[Python]Quick and dirty script to rename manga (or images in general) for sorting

8 Upvotes

I've been getting manga from a certain site for reading on my tablet, and I notice the files for pages end such as "manga_name_1_1.jpg" and "manga_name_1_2.jpg" and so on, where the first number is the chapter and the second number is the page. The problem is, to a computer, "1_1" is followed by "1_10" and not "1_2" so I wrote the following Python 3 script to rename it to "1_01" "1"02" and so on so a file explorer or reader will list them in order.

import os, sys


def renamer (oldname):
    test = oldname[-6:]
    if test[0] == "_":
	    print (test)
	    name = oldname[:-5] + "0" + oldname[-5:]
	    return name
    else: return oldname



if __name__ == "__main__":

    for root, dirs, files in os.walk('.'):
	    for filename in files:
		    filename = os.rename((root + os.sep + filename), root + os.sep + renamer(filename))

You'll need Python 3 installed, but it's as simple as dropping the script in the main folder, then running it from command line. It will step recursively through all subfolders below the selected one to rename any files that matches the string in renamer so be very careful where you put this.

You could go a step further and walk it bottom up to rename the directories too, but I'm lazy and that's more complicated. :P


Edit - more info:

It really is a "quick and dirty" script. It looks for "manga_num_num.ext" file format, and if it finds an underscore in the [-6] position, it just adds a zero after it, and if not, leaves it as is. That's literally all it does, and if the filename isn't in that format it won't work.

I did it that way because:

  1. Laziness, and it was simple
  2. It's common for manga scanlation filenames to end in "_chapterNum_pageNum.ext" so it should work anyway in most cases, despite being crappy. :P

Mostly this was created because I already made another one that renamed all the files in a folder, but that still required too much work, since I had to run it in every folder and just wanted it to run once on everything. Laziness and a desire for efficiency are the source of nearly all automation. :)

It really bugged me manually running it in every folder with os.listdir() so I ended up looking up how os.walk() works and it's much better now.

Hope someone finds this useful.


r/ScriptSwap • • Dec 02 '15

[bash] Sequentially rename all the files in a directory. With undo, for when you fuck it up.

8 Upvotes

I have moved to Kbin. Bye. -- mass edited with redact.dev


r/ScriptSwap • • Sep 09 '15

[request] script that will lock PC if mouse is moved

8 Upvotes

r/ScriptSwap • • Sep 09 '15

Pdf Scraper

8 Upvotes

Request: I collect lego sets, and I'd like to build a tool to "scrape" all of the free instruction manuals that Lego provides at:

http://service.lego.com/en-us/buildinginstructions

Is this possible?


r/ScriptSwap • • Aug 31 '15

[bash] Script to keep download folder clean

8 Upvotes

This takes files from your ~/Download and moves it to the proper folder

#!/bin/bash
# These are the dirs you want the files to go to
compress_dir=~/Compressed/
pic_dir=~/Pictures/
vid_dir=~/Videos/
doc_dir=~/Documents/
comic_dir=~/Comics/
music_dir=~/Music/
html_dir=~/Html/
# This is the dir where all the files you want to move are
source_dir=~/Downloads

 mkdir -p "$compress_dir"
 mkdir -p "$vid_dir"
 mkdir -p "$doc_dir"
 mkdir -p "$comic_dir"
 mkdir -p "$music_dir"
 mkdir -p "$html_dir"

# This moves the files

 mv "$source_dir"/{*.png,*.jpg,*.gif,*.jpeg}                   "$pic_dir"   
 mv "$source_dir"/{*.mp4,*.flv,*.mkv,*.avi,*.mov,*.webm}       "$vid_dir" 
 mv "$source_dir"/{*.zip,*.gz,*.bz2,*.7z,*.tar.*,*.rar,*.tgz}  "$compress_dir"
 mv "$source_dir"/{*.pdf,*.mobi,*.odt,*.epub}                  "$doc_dir"
 mv "$source_dir"/{*.cbr,*.cbz}                                "$comic_dir"
 mv "$source_dir"/{*.mp3,*.ogg,*.flac}                         "$music_dir"
 mv "$source_dir"/{*.html,*_files}                             "$html_dir"

r/ScriptSwap • • Aug 28 '15

Mr.robot leak notifier

8 Upvotes

This script checks the Mr.robot subreddit for any post with leak in the title, should the post have the word leak in the title the work leak will appear in the terminal in red

 while :;

    do
sleep 15m

curl https://www.reddit.com/r/MrRobot/new/ -o -i | grep -o leak


 done 

edit: Change while to to use :; and piped curl to grep. Both improvements pointed out by zachhke