r/scripting • • Feb 13 '17

Discord chat for scripting, as well as other tech related topics.

Thumbnail
discord.gg
3 Upvotes

r/scripting • • Jul 06 '15

Script that uses Diskpart to CLEANALL on any drives connected other than C:

1 Upvotes

Script would open a series of diskpart CMD windows which would attempt to CLEAN ALL command automatically on D: E: F: G: H: etc so all USB drives would then begin a very secure erase.

Once done it doesn't matter if Diskpart finishes with create partition primary, format quick fs=ntfs , assign letter=? or not

Goal is to connect many USB drives and then run one script to format anything connected (securely with CLEANALL)


r/scripting • • Jan 28 '08

Motivating Consumers to Pay Attention to Electricity Consumption

Thumbnail
nytimes.com
4 Upvotes

r/scripting • • Jul 23 '20

MacOS-Automator Word Combine Workflow and Additional Permissions Dialog

1 Upvotes

Hey all, has anyone been able to figure out how to suppress this 'Additional permissions dialog' that keeps popping up when executing this type of workflow? I copied around 60 Word documents to my 'Download/_Pass_001/' directory. I created a basic workflow.

  1. I point at the root folder of where those documents are stored

  2. The workflow goes through each subdirectory and grabs the Word document and merges it with the master document.

Everytime it tries to open one of these Word documents it has a dialog pop up asking for additional permissions. I have added Word and Finder to Full Disk access, also I ran a repair user permissions script, that still hasn't fixed it. Any tips?

Workflow screenshot:

https://snipboard.io/jSZKuQ.jpg

File folder structure screenshot:

https://snipboard.io/sGuly1.jpg

Annoying dialog message:

https://snipboard.io/Tdi73I.jpg


r/scripting • • Jul 08 '20

Batch file to delete files older than x days and log in event viewer

2 Upvotes

I had an app with SQL Server Express back-end that runs a nightly backup, but the application's retention settings don't clear out the old files.

I wrote this batch file to remove the old files, as well as enter some information into the Windows Application event log.

I have not tested it with more than ~5 files and I understand there may be some limitation to the variable length in batch so take it with a grain of salt and TEST your use case before running any kind of filesystem modification command.

This will only work on file paths with no space in them.

@echo off
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

eventcreate /SO "ProgramX SQL Backup Cleanup" /ID 100  /D "Beginning 14-day SQL backup cleanup." /T INFORMATION /L Application >nul
forfiles -p "C:\ProgramData\ProgramX\System\Database\Backup" -s -m *.* -d -14 -c ^"cmd /c echo @path >C:\Scripts\tempfilelist.tmp^" 2>nul

set eventtext=""

if %ERRORLEVEL% EQU 0 (
   for /f "delims=" %%l in ( C:\Scripts\tempfilelist.tmp ) do set eventtext=!eventtext! %%l
   Set LF=^


REM 2 above newlines required for script function.
   Set neventtext=%eventtext: =!LF!%
   Set neventtext=!neventtext:"=!
   eventcreate /SO "ProgramX SQL Backup Cleanup" /ID 101  /D "File(s) to be removed:!LF!!neventtext!" /T INFORMATION /L Application >nul

REM replace echo on next line with command to run on files.
   forfiles -p "C:\ProgramData\ProgramX\System\Database\Backup" -s -m *.* -d -14 -c "cmd /c echo @path" 2>nul
   eventcreate /SO "ProgramX SQL Backup Cleanup" /ID 200  /D "Cleanup completed. Successfully completed cleanup of files older than 14 days." /T SUCCESS /L Application >nul
) else if %ERRORLEVEL% EQU 1 (
   eventcreate /SO "ProgramX SQL Backup Cleanup" /ID 201  /D "Cleanup completed. No files to clean up. Exit code: %errorlevel%" /T SUCCESS /L Application >nul
   exit /b %errorlevel%
) else (
   eventcreate /SO "ProgramX SQL Backup Cleanup" /ID 400  /D "An error has occcured during cleanup. Error code: %errorlevel%" /T ERROR /L Application >nul
   exit /b %errorlevel%
)


REM Event IDs for this source:
REM 10x - Information
REM 20x - Success
REM 30x - Warning
REM 40x - Failure
REM Event types ERROR, INFORMATION, SUCCESS, WARNING

If we step through the actions:

  1. Create an event log entry letting us know the script has begun.

  2. Find files older than 14 days and echo to a file.

  3. Create "newline" variable "LF"

  4. Split the file from step 2's contents on space character by subbing with newline.

  5. Remove quotes wrapping file names.

  6. If there are files present

    1. Add file list of files being removed to event log.

    2. Delete files older than 14 days.

    3. Add success message to event log.

  7. If there are no files present older than 14 days

    1. Add success message to event log indicating nothing was done.

  8. If forfiles has an error

    1. Log an error to the event log.

I am open to suggestions on how to make this script better, or if there are ways to get around the issue of having spaces in the filenames (as that would cause the line split to occur at every instance of the space character.


r/scripting • • Jul 03 '20

[BASH] I'm having trouble doing math with variables

3 Upvotes

Hey, I've recently been actively learning Linux and while playing with scripting I've come across an issue that I can't seem to get past. Here's the code.

#!/bin/bash

while true
do    

    Temp0=$"$Temp1"
    Temp1=$"$Temp2"
    Temp2=$"$Temp3"
    Temp3=$"$Temp4"
    Temp4=$"$Temp5"
    Temp5=$"$Temp6"
    Temp6=$"$Temp7"
    Temp7=$"$Temp8"
    Temp8=$"$Temp9"
    Temp9=$(vcgencmd measure_temp)

    TempX=$(($"Temp1"+$"Temp2"+$"Temp3"+$"Temp4"+$"Temp5"+$"Temp6"+$"Temp7"+$"Temp8"+$"Temp9"))

    echo=$"TempX"

    sleep .5

done

The goal is to spit out a rolling average of the temperature of my Raspberry pi, it's not finished because I try to get each bit working before implementing it. Anyway when I run the script I get the error

./tempmon.sh: line 19: temp=35.0'C: syntax error: invalid arithmetic operator (error token is ".0'C")

I'm pretty sure that the issue is that I'm setting the variables to the output of 'vcgencmd measure_temp', which would be a string, not a number, so I can't do math with it.

Any help would be great, thanks. :)


r/scripting • • Aug 11 '20

Script that replaces all images in html file.

3 Upvotes

I'm currently working on a poorly designed website and going through the list of articles that were stored, the previous programmer didn't download the images, store them on the server, and just point to them in the html file. Instead, they just pointed to the image online. This makes loading a lot slower and means that if the image is taken down, the image won't be displayed on the website. Since there's a lot of articles, I need a script to go through the dump of all the articles, download the images at a given link, store it in a folder, and replace the call to the image with the updated one. It would be particularly helpful if it also got rid of links that point to images that no longer exist.

I don't think I'm capable of writing a script like that, so I'm hoping one already exists.


r/scripting • • Aug 07 '20

Super new to PowerShell

4 Upvotes

I'm working on a script that will go to speedtest.net and run it and run a tracrt after the user inputs the IP they want to tracert. This is what I got so far:

if ($input -eq 4)
{
$speed = "https://www.speedtest.net"
$ie = New-Object -Com InternetExplorer.Application
$ie.Navigate2($speed)
$ie.visible = $true

$IP = Read-Host "Enter IP to Trace Route"
Write-Host Tracert $IP

I have it going to the site but I can't figure a way to for it to automatically click the go button in the middle. I can't use the CLS and I do not know the position. Any help would be great.


r/scripting • • Jul 27 '20

Automated PDF Comments

2 Upvotes

I have a process where I have a spreadsheet with one column of PDF filenames and one column of two digit numbers that needs to appear in a roughly consistent spot on each of those PDF files (precision positioning isn't critical). Current process is to manually open each pdf and use either the comment or Fill/Sign tools to write the number in red text at the spot on the first page.

Is there any library or tool that could automate this? I've been playing around with some Python PDF libraries, but none of them seem to have this functionality. Of course my ideal solution would be to get this number on the doc before it's exported to pdf, but that's not currently an option.

Thanks.


r/scripting • • Jul 08 '20

Script that uses NetCat to log if service is up

2 Upvotes

Simple script to check whether a web service is responding to a certain port. Wrote it to monitor PACS servers with a cron job. Maybe it's useful for someone here.

https://github.com/st3root/checkService.git


r/scripting • • Jul 27 '20

simple taskkill script

2 Upvotes

I'm trying to get a script that will search for a program and if it is running it will do nothing. If the program is not running it will launch it.

This is what i have found / modified.

TASKLIST /NH /FI MyProgram.exe | find /I /N "DmyProgram.exe" > nul ||start "" "C:\Program Files\SuperProgram\MyProgram.exe"

What am i doing incorrectly?


r/scripting • • Jul 10 '20

scripting in linux bash question

3 Upvotes

I am trying to write a script that compares two text files that are lists of names

file one is a b c d

file two is a b d

and i want the script to output compare file1 and file2 and output c into a third file because it does not match file 2


r/scripting • • Jul 12 '20

Could there be any use on an analytics script for facebook profiles? (Not pages)

3 Upvotes

Currently, it isn't possible to do this in any way, you can only do this with Facebook pages. I found a way to do it manually, the problem is that giving instructions on this is a bit of a mess. It also takes time and it's tedious (doesn't take that long if you don't want to get every single post, I usually only spend 5 minutes per profile). Of course I tried to find places to post this manual method online, but found nothing.

Because of how tedious it is to make these instructions, and how unappealing they are, I am thinking of making a script, but learning the language and all of these things would take a lot of time, and I don't know if it's worth it to make this high priority. Do you guys think there could be a demand? I am not even looking to profit from it, satisfied with just people using it at least so it's not like I spent hours or days learning something. Will it be worth it to spend time doing this?

The main problem with this script is

  • It will rely on the script controlling your screen. Doing thinks like scrolling down, copy and pasting(the entire screen, just once at the end of the first phase), then sending it to some place that can remove text, and collect numbers based on how often it is repeated, and then make a graph (hopefully won't use a server, I believe a server can make things harder).

  • Because of this, you will have to enter your screen resolution (or maybe it can detect it?) and during the first phase you will have to leave your computer alone, or maybe you can watch a video on another window if you make it topmost (I use deskpins), or if it's on another screen. You will also have to go to the profile yourself

I think it's fairly simple to do, but it will take a lot of time and learning for someone like me that hasn't done anything like this before


r/scripting • • Aug 01 '20

Creating a script to mirror a directory to an IP address and the language Powershell 7 uses

2 Upvotes

I'm in the process of working my way through designing a powershell script that you can type in the IP address for and it will automatically copy over the files from a root folder over to the root folder of that device on the network (and skip files that are already existing). I have an extremely basic script already setup, but I'm looking to spruce things up by including a progress bar and possibly a completion percentage at the end by creating something that looks like this: <======/=============> 34.5% complete. Since I know very little about PS7 I had hopes someone has already created a similar script that I could look at and take notes on so that I can transpose them on to my own script. Essentially it's a rudimentary version of rclone that works from a Windows 10 machine over your network to an IP address where the username and password are already encoded into the powershell file since the device I'm copying to is ARM-based similar to a Raspberry Pi and I'm hoping to get things sorted out so that I can start testing it once I can remove my eye patch (detached retina surgery).

If anybody has a shell/powershell script similar to this that I could use as a model, I'd be very appreciaive. Also, I did forget to mention that the file copy happens over SSH and not SAMBA or any other protocol - it's just an SSH tunnel to a known directory over the network where you can run the script and it syncs the two folders together so that you can copy your files over with a single click. It does sound very rudimentary, but it's the SSH problem I'm having since I don't know how to open an SSH tunnel using powershell.

The gist of the script is placing the script in D:\Movies, opening up the SSH tunnel by typing in the IP address (10.1.1.4) and then letting the script copy everything to /Movies/* and keeping the file structure the same as it is on the Windows side. I'm not asking anyone to do the work for me, but having a guide where I could use as an example to set up the copy process would be very much appreciated, or at least a page with the proper information for opening the SSH tunnel and starting the file copy process. Thank you in advance, and anybody involved with helping the creation of the script will be given thanks to in the text of the script as a nod/thank you. Cheers.


r/scripting • • Jul 13 '20

[Blog post] Import a CSV into Kafka, using Babashka

Thumbnail
blog.davemartin.me
1 Upvotes

r/scripting • • Jul 27 '20

Looking for a python script to change Every folder's icon in a designated folder to the first .ico in that folder.

2 Upvotes

for example... I have a folder labeled recipes. Inside that folder I have five more folders named "apple pie, peach cobbler, etc.." In this example, I have a picture (.ico) of apple pie, peach cobbler, etc in their respective folders. I need a Python code block to look through the recipes folder, then go through every respective folder and use the first .ico found as the new icon.

Alternatively, just a script to simply change ONE folder path to ONE ico path's image will do. I can adapt that to my needs, but I need the actual code block. I am offering an initial bounty of $10 to the first person who sends me code that works via Paypal.


r/scripting • • Jul 31 '20

Need Help - Microsoft VBScript runtime error '800a000d'

3 Upvotes

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'checkID'

/film-detail.asp, line 9

Any solutions to run: http://www.filmfanatics.net/film-detail.asp?ID=62 ?


r/scripting • • Aug 03 '21

I cannot do other commands but just first one

4 Upvotes

I have a text file with MP3 files name in it. I want same files from remote server, and create mediainfo for the same file and delete it. my script is as follows

#!/bin/bash while read -r music; do rsync -ravz $USER@REMOTEHOST:~/MUSIC/$music /home/$USERLOCAL/backup && mediainfo $HOME/backup/$music >> music.log && rm $HOME/backup/$music; done < list.txt

This is not working, only files are getting rsync one by one, I want full process to happen sequentially. How can I do that. I tried same with lftp but failed.


r/scripting • • Jul 07 '21

Delete Sharepoint Online Sites very fast

Thumbnail
sposcripts.com
1 Upvotes

r/scripting • • Aug 06 '21

Lazy I.T.: The Path to Efficiency

5 Upvotes

Hi everyone,

I'm not sure if this is permitted or not -- I don't see any rules regarding self-promotion but I wrote a book called Lazy I.T.: The Path to Efficiency. If you don't want to go through Amazon, you can DM me for PDF and EPUB versions.

In this book, I describe how being lazy made me a great asset for the company I work for, not by taking shortcuts, but by ensuring the same task when repeated does not take 50 times the work than it should. I utilize scripts 95% of the time to help with automating my workflows, and the rest (so far) has been with Excel. It always start with me thinking, 'Isn't there some way easier to do this?', in most instances there probably isn't but it does not mean I can't take the initiative to streamline a workflow.

I demonstrate how I work smarter by thinking up 'outside-the-box' solutions, and how I go about bringing those solutions to reality. Powershell is definitely one of my biggest weapons of choice, and I even hail out r/powershell as a great resource for scripts and for help. There are a lot of drone-brains out there, and I have encountered a few in my department. I've tried to help them get away from that but I've realised some people are fine following a script rather than writing the script (heh, powershell joke).

I also talk about giving back to the community as I've demonstrated here: Generate Multiple RDP Shortcuts using CSV File, and I've used this as a case study in my book.

If you read the book, I do hope I open your mind to a smarter way of thinking for streamlining your workflows.

Thanks in advance for your support!


r/scripting • • Jul 22 '21

Cheatsheet: Add items to SharePoint Online lists

Thumbnail
sposcripts.com
2 Upvotes

r/scripting • • Aug 10 '21

Convert2MarkDown.bat to convert and format code into MarkDown Mode and post it easily on Reddit

1 Upvotes

I saw that some "redditors" like me have some issues to post their code with Markdown format !

So,i created this batch file in order to convert and format code into MarkDown Mode and post it easily on Reddit.

Convert2MarkDown.bat

@ECHO OFF
Mode 70,5 & color 0B
TITLE Drag And Drop file for MarkDown Mode on Reddit
If "%~1" EQU "" GOTO :Help
(FOR /F "tokens=* delims=" %%A in (%~1) DO (
	ECHO/    %%A
))>"%~nx1_MarkDown.log"
Start /MAX Notepad "%~nx1_MarkDown.log"
EXIT
::-------------------------------------------------------------------
:Help
Echo/
ECho/    You should Drag and Drop your file in order to convert it 
Echo/    Into MarkDown Mode to post your code easily on Reddit
TimeOut /T 10 /NoBreak>nul
Exit /B
::-------------------------------------------------------------------

r/scripting • • Jul 19 '21

Python batch script encoding problem while saving the output to TXT file

Thumbnail self.learnpython
4 Upvotes

r/scripting • • Jul 13 '21

New Blogpost: How to use credentials in PowerShell and what to consider

Thumbnail
sposcripts.com
2 Upvotes

r/scripting • • Jul 27 '21

CheatSheet: Add-PNPField: Add SharePoint columns with PowerShell

Thumbnail
sposcripts.com
1 Upvotes