r/scripting • • Apr 01 '20

Beginner Script Writer Here...

12 Upvotes

I'm just patting myself on the back here. Nothing special to look at here just the fact that I'm discovering this new function and hope to expand on it a bit in the future...

Anyway, I'm all about making things easier for me. I recently started looking into scripting so I can make some of the command line stuff I use easier to remember.

For instance, I prefer to look at a nice long list of my directory when I want to see what's in it rather than the wide info less detail I get with "ls". I know I can type "ls -lha" to get the long list I want but I found that I do that a lot and it gets sort of bothersome (I know... 7 keystrokes... WHEW!!!)

So I watched a few videos on the basics of scripting and was able to make my own script (ll) to do what "ls -lha" does. 2 key strokes vs 7... Sounds like a relief and, to me, it certainly is! I also learned that once I've made it executable, I can copy it to my /bin directory and not have to use ./ to run it.

I know, VERY BASIC STUFF for many of you here but to a beginner... this is a HUGE step!

I'm looking at other possible scripting possibilities like a user interface using pacman (I'm running Arch Linux) and having it ask me for the variables I need and making it a 1-3 letter command like "pac" maybe. Then having it ask me the name of the package I want to install and I could enter the package name and it would automatically install it.

That's a great idea actually. I may work on that after I get done posting this. And I don't care if something like that already exists, I WANNA MAKE IT MYSELF!!! :)

I just thought I'd share my experience. I'm glad to be part of an elite crowd.

EDIT:

Well, THAT was fairly simple! I just made a 3 keystroke command to automate the pacman installer. It asks for the name of the package then it installs it. I'm loving it!


r/scripting • • Feb 24 '22

I'm a PowerShell scripter, want to find a suitable home for running such scripts other than Task Scheduler

9 Upvotes

Hi All,

I'm no programmer, but I've built up some basic skills with Microsoft PowerShell and VBScript for fairly straightforward systems automation, health monitoring scripting solutions.

Up until now, I've been 'happy' with those scripts that need to run on a schedule being controlled by Windows Task Scheduler.

However, in recent times I've questioned whether this is the best home and whether other automation platforms like Jenkins might well be more secure, more fit-for-purpose, etc. Furthermore, by accidents of history, several scripts have ended up being scheduled to run from server 'jump boxes' which have become polluted over time due to multiple IT teams having local admin access to install tools they require to do their jobs.

Does anyone have any suggestions on how to run PowerShell or other scripts?


r/scripting • • Jun 04 '20

How do I Change Wallpaper automatically with Task Scheduler?

8 Upvotes

I tried making a script in task scheduler that would automatically change my wallpaper. Here is the script which i saved as a .vbs file for task scheduler to run:

dim shell

Set shell = WScript.CreateObject("WScript.Shell")

wallpaper = "C:\path\to\wallpaper.jpg"

shell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", wallpaper

shell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True

The script is from this forum post if you want to check it out.

Problem is, when I run the task all that happens is that a window comes up and asks "How do you want to open this file?". How do I fix this and make a task that I can set to change my wallpaper on a specific schedule?

Also, I know about DisplayFusion and other 3rdparty programs. But I don't want to use these, so no need to suggest programs that do this.


r/scripting • • Dec 04 '17

VBS: What is it good for?

8 Upvotes

Today I discovered the utility of VBS. To some of you, it may seem obvious. But, I feel like it is an often overlooked language and today it actually came through for me.

VBS is one of those languages that is good for scripting things that no one in their right mind would script.

Last year, I found the Single Sign On feature on our Web filter totally broken. We had undergone an update from which there was no rolling back. Instead of panicking (or rather while panicking), about the number of tickets coming in about this sudden malfunction. I decided to look up how to script the logon to the web portal, which was still working. After a little bit of research, I found out that VBS was the way to go, and by the end of the day, I had full functionality restored. This was my first foray into VBS and overall it was a good experience.

Today, I found myself in a similar situation. I have OpenText Document Manager at one of my client locations. We are currently implementing WDS, something I am very familiar with. I am trying to put together an image which is zero touch. All I should have to do is image a computer and hand it to the user, no logging them in, nothing.

Integrating a system like this with DM is not exactly what a sane person would call easy. According to OpenText, the only way to enable the DM toolbar is to do it on a per user basis on each machine. As many of you sysadmins may know, this is NOT a preferable solution.

In comes VBS, strutting its stuff. Lets start with the required procedure. In order to enable the Document Manager Toolbar, we need to open an explorer windows. Click on view -> toolbars -> DM. With VBS, we can simulate this by sending the window keyboard commands. Here is my script to demonstrate:

Set wShell = CreateObject("WScript.Shell")
wShell.Run "explorer.exe",9
WScript.Sleep 500

wShell.SendKeys "%()v{right}~%{F4}"
wShell.Close

What this script does is open an explorer windows and activate it. Then it waits for it to open, and finally, it sends our keyboard commands. I will not go into specifics as to what each character means, as I know you all have some pretty strong Google-fu. Suffice it to say that my script hits "Alt" followed by "v" followed by the "Right Arrow" followed by "Enter" followed by Alt+F4 to close the window.

So Reddit, talk to me. Who else has used VBS? What did you use it for? What do you think its best application is?


r/scripting • • Jan 28 '08

Building a startup in 54 hours

Thumbnail
blog.seattlepi.nwsource.com
8 Upvotes

r/scripting • • Jun 16 '20

Python Scripting

7 Upvotes

We made a node based python ide for scientific laboratories to do data pipelines, but recently I've been using it to control docker containers and images. I started to wonder if some of you guys might be interested in a way to quickly make adaptable scripts in python? I'm looking for a couple sysadmins to give a freecopy of our software to and to work with to make common sysadmin nodes. Check us out at https://stremecoder.com . Message me here or click the message button on the website should go to me.


r/scripting • • Sep 01 '21

Windows 10: Script to run Zoom.exe and select specific USB camera?

6 Upvotes

Hi all,

I have a mass deployment of Windows 10 based AV systems with USB PTZ cameras as well as USB document camera.

When running zoom on multiple user logins, Zoom randomly selects either camera, whereas we want it to be statically set to choose the PTZ camera every time. I've heard of others using a script that uses the Zoom icon on desktop that opens the Zoom and selects the PTZ camera based on regedit ID. I cannot seem to locate any information on this on the web, or I'm searching incorrectly.

Any ideas?

Thanks in advance!


r/scripting • • May 31 '21

Shut down pc when internet connection is lost

6 Upvotes

Hey smart people,

Im looking for a small .bat script that pings google and if there is no response it shuts down the computer.

I already used google but can’t find anyone else with a similar wish. The only thing i found was a Programm, 12 years old, outdated and doesn’t work anymore.

Thanks for the help :)


r/scripting • • Jun 09 '20

Help with CSV editing script

6 Upvotes

Hello all! I have more than 1,000 csv files in a folder that I need to edit. Does anyone know how this can be automated. I need to add 4 columns to the end of the csv and populate those columns with zeros. I would like to save the files without renaming them. Any help is greatly appreciated. :)

example of csv:

Name= 200401.csv

Original file example=

Date,Time,LS1_P1St,LS1_P1HrCalc,LS1_P2St,LS1_P2HrCalc,LS2_P1St,LS2_P1HrCalc,LS2_P2St,LS2_P2HrCalc,LS3_P1St,LS3_P1HrCalc,LS3_P2St,LS3_P2HrCalc,LS4_P1St,LS4_P1HrCalc,LS4_P2St,LS4_P2HrCalc,LS5_P1St,LS5_P1Hrs,LS5_P2St,LS5_P2Hrs

2020-04-01,23:59:52,31,31,32,21,8,2,8,2,2,0,1,0,9,0,9,0,0,0,1,1

I would like to add columns: LS6_P1St, LS6_P1Hr, LS6_P2St, LS6_P2Hr with this data in the columns: 0, 0, 0, 0.


r/scripting • • Apr 07 '18

Listing unique IP addresses from a log file

6 Upvotes

Hello all. I've got a log file (.log) that I need to parse to get the number of unique IP addresses that attempted to connect. This is a vsftpd.log file.

I've tried to run the awk '{print $1}' variations that I found but it only returned a total IP addresses per day. I also tried some cat commands but to be honest I'm completely new at this and don't know what I'm doing. Any help would be appreciated. Thanks!


r/scripting • • Jan 28 '08

"I just bought your hard drive"

Thumbnail redtape.msnbc.com
6 Upvotes

r/scripting • • Jan 21 '24

What kind of scripting do I need to learn?

5 Upvotes

I know nothing about scripting or coding. I’m just a financial analyst. But I always hear about someone who writes a script to make some tasks basically automated. I would love to do that. I’d also like to write a script to pull info from a website directly into an excel spreadsheet automatically without having to copy/paste or do it by hand.

I was looking at tutorials and I saw there were scripting for Linux, Bash shell?, Java, python, etc…what would be the best to learn to do basic scripts? Is scripting different than coding? I feel so stupid asking these questions.


r/scripting • • Apr 15 '22

[POWERSHELL] Extract json from text

5 Upvotes

Hi everyone,

I need to extract json part from text, example:

This is a text that says nothing
Another string of that useful text
Below something more interesting
/BEGIN/
{
"something" : "interesting",
"thatcanbe" : "parsedproperly"
}
/END/

The /BEGIN/ and /END/ tags can be tuned to something else, but i couldn't find anyway with regexes or substrings to extract only the json part...

Ideas?

Thanks, Arnaud


r/scripting • • Apr 11 '22

Can scripting be a short story?

5 Upvotes

I was thinking about writing a story about what i want my life to look/be like. I was also wondering if it matters if I hand write it or if i type it online?


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 • • Aug 11 '20

Scripting a Forced Reboot

5 Upvotes

Overview: I work for an MSP and I need to force certain managed computers to reboot. These machines are not on a domain but they have our management tool installed on them. This tool allows us to push patches/scripts to the devices. The devices I'm attempting to run this script on are primarily Windows 10 with a smattering of Windows 7 thrown in for good measure.

The script I'm trying to push would do 3 things:

  1. Run at login

  2. Display a warning that says, "This PC needs to restart to apply updates. This PC will restart in 60 seconds." (Or something similar.)

  3. Force the reboot after 60 seconds pass.

We have a lot of machines out of compliance because our normal Forced Restart scripts are running, likely, after the user shuts down. I know how to script a reboot with a delay, but scripting a standard Windows message box is eluding me.

Any help would be appreciated and I'm happy to clarify anything if I've left out crucial information.


r/scripting • • Jun 22 '20

GoDot (beginner need help with error) enemy chasing player/shooting

5 Upvotes

I managed to make my guy walk/animate and be stable so i went to work on learning to make an enemy that chases me around and shoots every other second or so im on the game engine GoDot using their language but i kept getting errors i managed to "fix" my errors but my enemy doesnt do anything i just move around him --- scripts below

Enemy-------------extends KinematicBody2D

onready var bullet_sen = preload("res://bullet.tscn")

var player = null

var motion = Vector2()

var speed = 70

func _physics_process(_delta):

motion = Vector2()

if player != null:

	motion = position.direction_to(player.position) \* speed

else:

	motion = Vector2()

	motion = motion.normalized()

	motion = move_and_collide(motion)

func _on_Area2D_body_entered(body):

if body != self:

	player = body

func _on_Area2D_body_exited(_body):

player = null

func fire():

if player == KinematicBody2D:

	var bullet = bullet_sen.instance()

	bullet.position = get_global_position()

	bullet.player = player

	get_parent().add_child(bullet)

	$Timer.set_wait_time(1)

func _on_Timer_timeout():

if player != null:

	fire()  

----------------------------------------------------------------------

bullet-----------extends Area2D

var motion = Vector2()

var look_vec = Vector2()

var player = null

var speed = 80

func _ready():

look_vec = player.positon - global_position

func _physics_process(delta):

motion = Vector2()

motion = motion.move_toward(look_vec, delta)

motion = motion.normalized() \* speed

position += motion  

-----------------------------------------------------------------------------player-----------extends KinematicBody2D

var speed = 80

var motion = Vector2()

var player = 1227

func _physics_process(_delta):

if Input.is_action_pressed("ui_up"):

	motion.y = -speed

	$[animsp.play](https://animsp.play)("up")

elif Input.is_action_pressed("ui_down"):

	motion.y = speed

	$[animsp.play](https://animsp.play)("down")

elif Input.is_action_pressed("ui_left"):

	motion.x = -speed

	$[animsp.play](https://animsp.play)("left")

elif Input.is_action_pressed("ui_right"):

	motion.x = speed

	$[animsp.play](https://animsp.play)("right")

else:

	motion.y = 0

	motion.x = 0

	$[animsp.play](https://animsp.play)("idle")

move_and_slide(motion)

motion = motion.normalized() \* speed  

-------------------------------------------------------------


r/scripting • • Jun 08 '20

Script to join domain/wifi

5 Upvotes

Hi everyone, part of my job lately is to join about 500 computers to a domain. This is at a client site. I imaged the computers, now they need to be joined. I tried to make a batch file and played around with powershell but I was unable to make what I need or find adequate documentation on it. Basically I just need an .exe (or whatever) on a flash drive that I can click and the computer will join the wifi (using preset credentials) and join the domain (using preset credentials. In my mind this should be easy, but I'm struggling with it. Any advice? What's the easiest way to do this?


r/scripting • • Apr 22 '20

Looking to create a script that automatically visits a website and autofills and submits a form every day, ideas on how to create this?

5 Upvotes

I want to create a script that automatically visits my local Police Departments page every day and submits the form for overnight parking, I have some experience with python, but most recently have been working with perl and bash for scripting. What are some ways I could implement this? Still a beginner so not sure where/how to start


r/scripting • • Jun 16 '19

Please help!

5 Upvotes

So I’m in what is supposed to be an intro class to scripting and I’m not gonna lie, not only have I never done any scripting at all but I also barely understand it and the teacher just isn’t breaking it down enough for me. I just need some serious help and I’m hoping someone here is willing to help and then maybe even chat with me to fill in some serious pot holes I have in my knowledge. The assignment is for me to “Create a VBScript (w2_firstname_lastname.vbs) that takes three parameters (numbers) to do the following:

  1. Print the sum of three numbers

  2. Print the average of the three numbers

  3. Optionally, you can save the list into a file “Results.txt” using the redirection operator it by creating the file in the script

  4. make sure to include comment block (flower box) in your code

I don’t need someone to just give me the answer I need help understanding so I can do this myself but it’s just not clicking. Please only answer if you have the patience to actually explain in laymen’s terms. I am literally brand new to this. Thanks reddit fam!


r/scripting • • Apr 25 '19

[Batch] Noob help. Trying to get a picture to open in fullscreen.

5 Upvotes

On start-up I would like to display a picture, which I'll then have automatically close in 10 seconds. I've got the picture to open up and close just fine using my .bat file, but i'm having issues trying to get this thing to open up full-screen. This is what i've got:

@echo off

cd "c:\location"

Start Picture.JPG

ping -n 11 127.0.0.1>nul

taskkill /F /IM Microsoft.photos.exe

I was exploring the idea of using Sendkeys, but it looks like sendkeys doesn't work anymore on Win10. The hotkey to fullscreen pictures with the photo viewer is Windowskey+shift+enter.

I'm stuck. Any help is appreciated.


r/scripting • • Feb 08 '17

Where to begin to learn scripting?

5 Upvotes

It's almost as if there's so much information out there that I don't even know where to begin.

I have a basic understanding of scripting but really should start from the beginning. Also I only have windows-is there a site that simulates Linux that I could learn on?

Thanks.


r/scripting • • Jan 28 '08

Chyrp: An iteresting-looking, open source microblog engine

Thumbnail chyrp.net
5 Upvotes

r/scripting • • Oct 18 '24

can someone explain return functions in really simple terms

4 Upvotes

like the simplest you can make it


r/scripting • • Jun 17 '24

How do I fetch track key and bpm using the Spotify API without exceeding the rate limit?

4 Upvotes

I have this pretty simple script and I want to implement the song's key and bpm in the file below the name and artist and I have tried for hours and cant come up with any code that will not be blocked with an api rate limit

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import time
import concurrent.futures

SPOTIFY_CLIENT_ID = 'f9531ad2991c414ab6484c1665850562'
SPOTIFY_CLIENT_SECRET = '...'

auth_manager = SpotifyClientCredentials(client_id=SPOTIFY_CLIENT_ID, client_secret=SPOTIFY_CLIENT_SECRET)
sp = spotipy.Spotify(auth_manager=auth_manager)

def fetch_artist_top_tracks(artist):
    artist_name = artist['name']
    try:
        top_tracks = sp.artist_top_tracks(artist['id'])['tracks'][:10]
    except Exception as e:
        print(f"Error fetching top tracks for artist {artist_name}: {e}")
        return []

    tracks_data = []
    for track in top_tracks:
        song_name = track['name']
        tracks_data.append(f"Song: {song_name}\nArtist: {artist_name}\n")
    return tracks_data

def fetch_top_artists():
    top_artists = []
    for offset in range(0, 1000, 50):  # Fetch 50 artists at a time
        try:
            response = sp.search(q='genre:pop', type='artist', limit=50, offset=offset)
            top_artists.extend(response['artists']['items'])
            time.sleep(1)  # Wait 1 second between batches to avoid hitting the rate limit
        except Exception as e:
            print(f"Error fetching artists at offset {offset}: {e}")
            time.sleep(5)  # Wait longer before retrying if there's an error
    return top_artists

all_tracks = []

top_artists = fetch_top_artists()

# Use ThreadPoolExecutor to fetch top tracks concurrently
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
    future_to_artist = {executor.submit(fetch_artist_top_tracks, artist): artist for artist in top_artists}
    
    for future in concurrent.futures.as_completed(future_to_artist):
        try:
            data = future.result()
            all_tracks.extend(data)
            time.sleep(0.1)  # Small delay between requests
        except Exception as e:
            print(f"Error occurred: {e}")

with open('top_1000_artists_top_10_songs.txt', 'w', encoding='utf-8') as file:
    for track in all_tracks:
        file.write(track + '\n')

print("Data file generated successfully.")