Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "shell script"
-
*Now that's what I call a Hacker*
MOTHER OF ALL AUTOMATIONS
This seems a long post. but you will definitely +1 the post after reading this.
xxx: OK, so, our build engineer has left for another company. The dude was literally living inside the terminal. You know, that type of a guy who loves Vim, creates diagrams in Dot and writes wiki-posts in Markdown... If something - anything - requires more than 90 seconds of his time, he writes a script to automate that.
xxx: So we're sitting here, looking through his, uhm, "legacy"
xxx: You're gonna love this
xxx: smack-my-bitch-up.sh - sends a text message "late at work" to his wife (apparently). Automatically picks reasons from an array of strings, randomly. Runs inside a cron-job. The job fires if there are active SSH-sessions on the server after 9pm with his login.
xxx: kumar-asshole.sh - scans the inbox for emails from "Kumar" (a DBA at our clients). Looks for keywords like "help", "trouble", "sorry" etc. If keywords are found - the script SSHes into the clients server and rolls back the staging database to the latest backup. Then sends a reply "no worries mate, be careful next time".
xxx: hangover.sh - another cron-job that is set to specific dates. Sends automated emails like "not feeling well/gonna work from home" etc. Adds a random "reason" from another predefined array of strings. Fires if there are no interactive sessions on the server at 8:45am.
xxx: (and the oscar goes to) fuckingcoffee.sh - this one waits exactly 17 seconds (!), then opens an SSH session to our coffee-machine (we had no frikin idea the coffee machine is on the network, runs linux and has SSHD up and running) and sends some weird gibberish to it. Looks binary. Turns out this thing starts brewing a mid-sized half-caf latte and waits another 24 (!) seconds before pouring it into a cup. The timing is exactly how long it takes to walk to the machine from the dudes desk.
xxx: holy sh*t I'm keeping those
Credit: http://bit.ly/1jcTuTT
The bash scripts weren't bogus, you can find his scripts on the this github URL:
https://github.com/narkoz/...53 -
This code review gave me eye cancer.
So, first of all, let me apologize to anyone impacted by eye cancer, if that really is a thing... because that sounds absolutely horrible. But, believe me, this code was absolutely horrible, too.
I was asked to code review another team's script. I don't like reviewing code from other teams, as I'm pretty "intense" and a nit-picker -- my own team knows and expects this, but I tend to really piss off other people who don't expect my level of input on "what I really think" about their code...
So, I get this script to review. It's over 200 lines of bash (so right away, it's fair game for a boilerplate "this should be re-written in python" or similar reply)... but I dive in to see what they sent.
My eyes.
My eyes.
MY EYES.
So, I certainly cannot violate IP rules and post any of the actual code here (be thankful - be very thankful), but let me just say, I think it may be the worst code I've ever seen. And I've been coding and code-reviewing for upwards of 30 years now. And I've seen a LOT of bad code...
I imagine the author of this script was a rebellious teenager who found the google shell scripting style guide and screamed "YOU'RE NOT MY REAL DAD!" at it and then set out to flagrantly violate every single rule and suggestion in the most dramatic ways possible.
Then they found every other style guide they could, and violated all THOSE rules, too. Just because they were there.
Within the same script... within the SAME CODE BLOCK... 2-space indentation... 4-space indentation... 8-space indentation... TAB indentation... and (just to be complete) NO indentation (entire blocks of code within another function of conditional block, all left-justified, no indentation at all).
lowercase variable/function names, UPPERCASE names, underscore_separated_names, CamelCase names, and every permutation of those as well.
Comments? Not a single one to be found, aside from a 4-line stanza at the top, containing a brief description of that the script did and (to their shame), the name of the author. There were, however, ENTIRE BLOCKS of code commented out.
[ In the examples below, I've replaced indentation spacing with '-', as I couldn't get devrant to format the indentation in a way to suitably share my pain otherwise... ]
Within just a few lines of one another, functions defined as...
function somefunction {
----stuff
}
Another_Function() {
------------stuff
}
There were conditionals blocks in various forms, indentation be damned...
if [ ... ]; then
--stuff
fi
if [ ... ]
--then
----some_stuff
fi
if [ ... ]
then
----something
something_else
--another_thing
fi
And brilliantly un-reachable code blocks, like:
if [ -z "$SOME_VAR" ]; then
--SOME_VAR="blah"
fi
if [ -z "$SOME_VAR" ]
----then
----SOME_VAR="foo"
fi
if [ -z "$SOME_VAR" ]
--then
--echo "SOME_VAR must be set"
fi
Do you remember the classic "demo" programs people used to distribute (like back in the 90s) -- where the program had no real purpose other than to demonstrate various graphics, just for the sake of demonstrating graphics techniques? Or some of those really bad photo slideshows, were the person making the slideshow used EVERY transition possible (slide, wipe, cross-fade, shapes, spins, on and on)? All just for the sake of "showing off" what they could do with the software? I honestly felt like I was looking at some kind of perverse shell-script demo, where the author was trying to use every possible style or obscure syntax possible, just to do it.
But this was PRODUCTION CODE.
There was absolutely no consistency, even within 1-2 adjacent lines. There is no way to maintain this. It's nearly impossible even understand what it's trying to do. It was just pure insanity. Lines and lines of insanity.
I picture the author of this code as some sort of hybrid hipster-artist-goth-mental-patient, chain-smoking clove cigarettes in their office, flinging their own poo at their monitor, frothing at the mouth and screaming "I CODE MY TRUTH! THIS CODE IS MY ART! IT WILL NOT CONFORM TO YOUR WORLDLY STANDARDS!"
I gave up after the first 100 lines.
Gave up.
I washed my eyes out with bleach.
Then I contacted my HR hotline to see if our medical insurance covers eye cancer.32 -
I created a script with power shell that notifies me before I leave the office if my train is on time or isn’t. See the comment for another image of when the service isn’t on time!26
-
Well, I did it.
I spent 45 minutes writing my first hacky, shell-and-python automation script to save me 15 seconds every morning.12 -
Working on adjusting a shell script to my needs.
The fucker quits execution after an apt update command is ran.
No reason, it just fucking quits. No error messages or whatever, nothing.
This script can go suck a cock.9 -
TLDR: In defense of Powershell - the rant:
I don’t get the Powershell hate.
You don’t hate a screwdriver for not being able to turn a nut, you just *don’t use a screwdriver to turn a nut*
Once you recognize what the tool is good for and you don’t try to use it like Bash, it’s wildly powerful, and satisfying to use in a way Cmd.exe never was.
Cygwin or a Linux Subsystem can only go so far on a Windows computer. You’re dealing with two fundamentally different OS architectures. It makes sense you’d need different tools.
And like it or not, Microsoft owns the non-tech-user desktop , corners the non-tech server business market, and Active Directory is THE tool for managing Windows desktops on a large scale - So Wanblows is not going away anytime soon.
Automation without some weird ass sysVol batch login script is finally possible. Anyone who knows .Net classes can leverage their methods from directly within Powershell. Remote management of headless Windows servers is now a reality. If you have an Office 365 Exchange server you can literally Powershell remote to it for management, just like your favorite cloud hosted Linux distribution.
No one said Windows is a better OS, but an object based shell on an object based OS *makes sense*. It’s useful for its environment. Let it be.10 -
The gift that keeps on giving... the Custom CMS Of Doom™
I've finally seen enough evidence why PHP has such a bad reputation to the point where even recruiters recommended me to remove my years of PHP experience from the CV.
The completely custom CMS written by company <redacted>'s CEO and his slaves features the following:
- Open for SQL injection attacks
- Remote shell command execution through URL query params
- Page-specific strings in most core PHP files
- Constructors containing hundreds of lines of code (mostly used to initialize the hundreds of properties
- Class methods containing more than 1000 lines of code
- Completely free of namespaces or package managers (uber elite programmers use only the root namespace)
- Random includes in any place imaginable
- Methods containing 1 line: the include of the file which contains the method body
- SQL queries in literally every source file
- The entrypoint script is in the webroot folder where all the code resides
- Access to sensitive folders is "restricted" by robots.txt 🤣🤣🤣🤣
- The CMS has its own crawler which runs by CRONjob and requests ALL HTML links (yes, full content, including videos!) to fill a database of keywords (I found out because the server traffic was >500 GB/month for this small website)
- Hundreds of config settings are literally defined by "define(...)"
- LESS is transpiled into CSS by PHP on requests
- .......
I could go on, but yes, I've seen it all now.12 -
Wrote a custom printer script in shell.
Went to test the script on some printers.
Neglected to check accuracy of script.
script is supposed to print jpeg.
it doesn't interpret it as an image,
but rather as raw binary in text...
^\<92>Q^H2Ei@0$iA+<89>dl_d<87><8f>Q
mfw each printer in the entire 5 story building
starts printing 500 pages of
RAW
BINARY3 -
I need to make a confession. I wrote shell scripts that will automatically turn on my system and will download games and movies for me after office hours, using office internet10
-
I love Linux, but its community can be so full of incompetent assholes..
Just now I asked in Freenode ##linux how to get the process ID of my current running process in bash. I got my answer - it's a shell built-in called "$$".
Then people start to nitpick some more - why do you need it? How is that different from an exit? - to which my response was.. well I know the whole idea behind exit codes, and I'd use it whenever possible, in all defined behavior that allows my program to terminate itself whenever it can. This pidfile however would be used to exit itself and provide diagnostic information whenever the program enters undefined behavior - a segfault in C language. Scenarios in which I don't have full control over the script's behavior anymore, such as the system entering an unworkable state where the system stalled, still got some binaries in RAM but the rootfs got unwritable, such as now - very helpfully, thanks HP! - when my laptop likely overheated and shat itself. I issued sudo reboot into it, but even that wouldn't issue properly anymore due to the /sbin/poweroff binary becoming inaccessible too. I had to issue a hard power cycle.. one of the few times in which I'm thankful to HP for actually causing shit like this, lol.
Point is, that undefined behavior is what I'm trying to mitigate against. I certainly can't let any files other than diagnostics remain in nonvolatile storage like that, especially when their state should be predictable in order to ensure good operation (like files expressing whether the script is already running or not, i.e. lock files).
Back to that IRC chat. Aside from the answer, I got ridicule from people who probably don't even know how to properly compile a kernel. Ubuntu users, overconfident scum. Sometimes I feel like I should ask questions in channels like #archlinux only, where such incompetency is ridiculed on its own.13 -
What I was supposed to do today:
Finish up some homework and code for a bit
What I actually did today:
1. Boot up my laptop to get started on homework
2. Open Spotify and try to connect my headphones
3. Reinstall Bluetooth and pulseaudio to connect to headphones
4. Connected! But the sound quality is shit
5. Spend an hour or so learning about codec sinks and how Bluetooth is the definition of an overengineered clusterfuck
6. Install some package from the aur to get AAC codec support
7. Now we have high fidelity audio, but the headphones still connect to the crappy SBC sink, so I spend another 45 minutes writing a shell script to automatically switch to the AAC sink when a Bluetooth headset connects
8. It’s finally working! But now I have no motivation to do my actual work. Fml8 -
I just made a shell script that checks the ratings of movies that I have locally in IMDB and plays the one with highest score. #justsaying7
-
I was working for a startup that needed to update 300 machines that had just come from the factory. We had to open all 300 boxes and update them one at a time. I made a simple script that would run a folder full of shell scripts then keep track of what it ran so it would not run the same script twice. It made it so we could just plug the machines into the internet, they would query some server, download my program, and run it. It saved me from having to ssh into every machine and run commands. Well the head programmer guy saw what I did and implemented it as the main program that would update the entire machine. I didn't program anything into it to verify updates, the shell scripts did not return any indication of success or failure, and I made it in less than 3 hours. It was supposed to be a temporary program to be used for those 300 machines only, but ended up sticking around for 2 years.1
-
Our professor once asked us to 'mess up' the functionality of a PHP script with one shell command for fun. People tried different things like occupying the port, messing with access rights etc.
My friend just wrote a 'sed' command to replace all the underscores with an empty space...😂
It goes without saying that he stole the show.2 -
I showed a friend of mine a project I made in two days in Docker and Symfony php. It is a rather simple app, but it did involve my usual setup: Nginx with gzip/cache/security headers/ssl + redis caching db + php-fpm for symfony. I also used php7.4 for the lolz
He complained that he didn't like using Docker and would rather install dependencies with composer install and then run it with a Laravel command. He insisted that he wanted a non-docker installation manual.
I advised him to first install Nginx and generate some self-signed certificates, then copy all the config files and replace any environment-injected values (I use a self-made shell script for this) with the environment values in the docker-compose files.
Then I told him to download php-fpm with php 7.4 alpha, install and configure all the extensions needed, download and set up a local Redis database and at last re-implement a .env file since I removed those to replace them with a container environment.
He sent an angry emoji back (in a funny way)
God bless containerized applications, so easy to spin up entire applications (either custom or vendor like redis/mysql) and throw them away after having played with them. No need to clutter up your own pc with runtime environments.
I wonder if he relents :p9 -
That would probably be implementing multithreading in shell scripts.
https://gitlab.com/netikras/bthread
The idea (though not the project itself) was born back when I still was a sysadmin. Maintaining 30k servers 24/7 was quite something for a team of merely ~14 people. That includes 1st line support as well.
So I built a script to automate most of my BAU chores. You could feed a list of servers - tens or hundreds or more - and execute the same action on each of them (actions could be custom or predefined in the list of templates). Neither Puppet nor Chef or Ansible or anything of sorts was consistently deployed in that zoo, not to mention the corp processes made use of those tools even a slower approach than the manual one, so I needed my own solution.
The problem was the timing. I needed all those commands to execute on all the servers. However, as you might expect, some servers could be frozen, others could be in DMZ, some could be long decommed (and not removed from the listings), etc. And these buggars would cause my solution to freeze for longer than I'd like. Not to mention that running something like `sar -q 1 10` on 200 servers is quite time-consuming itself :)
And how do I get that output neatly and consistently (not something you'd easily get with moving the task to a background with '&'. And even with that you would not know when are all the iterations complete!)?
So many challenges...
I started building the threading solution that would
- execute all the tasks in parallel
- do not write anything to disks
- assign a title to each of the tasks
- wait for all the tasks to complete in either
> the same sequence as started
> as soon as the task finishes
- keep track of each task's
> return code
> output
> command
> sequence ID
> title
- execute post-finish actions (e.g. print to the console) for each of the tasks -- all the tracked properties are to be accessible by the post-finish actions.
The biggest challenges were:
a) how do I collect all that output without trashing my filesystems?
b) how do I synchronize all those tasks
c) how do I make the inception possible (threads creating threads that create their own threads and so on).
Took me some time, but I finally got there and created the libbthread library. It utilizes file descriptors, subshells and some piping magic to concentrate the output while keeping track of all the tasks' properties. I now use it extensively in my new tools - the ones where I can't use already existing tools and can't use higher-level languages.4 -
!rant
A rather long(it's 8 hrs long to be precise) story
So I just finished an amazing homework assignment. The goal was to open a new shell on Linux using a C program. We were asked to follow instructions from http://phrack.org/issues/49/14.html . However the instructions given were for 32 bit processors and we had to do same for 64 bit machines. In a nutshell we had to write a 64 bit shell code and use buffer-overflow technique to change the return address if the function to our shell code.
I was able to write my own shellcode within 1hr and was able to confirm that it's working by compiling with nasm and all. Also the "show-off-dev" inside me told me to execute "/bin/bash" instead of "/bin/sh"(which everyone else was going to do). After my assembly code was properly executing shellcode, I was excited to put it in my C code.
For that, I needed opcodes of assembly code in a string. Following again the "show-off-dev" inside me, I wrote a shell script which would extract the exact opcodes out of objdump output. After this I put it in my C code, call my friend and tell him that "hell yeah bro, I did it. Pretty sure sir is gonna give me full marks etc etc etc". I compiled the code and BOOM, IT SEGFAULTS RIGHT IN FRONT OF MY FRIEND. Worst, friend had copied a "/bin/sh" code from shellstorm and already had it working.
Really burned my ego, I sat continuously for 8 hrs in front of my laptop and didn't talk to anyone. I was continuously debugging the code for 8 hrs. Just a few minutes ago, I noticed that the shellcode which I'm actually putting in my C code is actually 2 bytes shorter than actual code length. WHAT THE F. I ran objdump manually and copied the opcodes one by one into the string (like a noob) and VOILA ! IT WORKED !!!
TURNS OUT I DIDN'T CUT THE LAST COLUMN OF OPCODES IN MY SHELL SCRIPT. I FIXED THAT AND IT WORKED !!
THE SINGLE SHITTY NUMBER MADE ME STRUGGLE 8 HRS OF MY LIFE !! SMH
Lessons learnt :
1)Never have such an ego that makes you think you're perfect, cuz you're retarded not perfect
2)Examine your scripts properly before using them
3)Never, I repeat NEVER!! brag about your code before compiling and testing it.
That's it!
If you've read this long story, you might as well press the "++" button.6 -
Today I was continuing my Ruby script for file encryption.
I added some features like Picture Encryption and Bookmarks.
Then I tried to start it to make sure it doesn't fuck up.
ruby PGCrypt.rb
No changes reflected.
w0t.jpg
Start debugging
Browses SO and DDG like a maniac
Reinstalls Ruby
Guess what happened.
My shell was in the wrong folder and I ran the old testing script.
GRAAAAAHHHH3 -
I'm OK with C language, but I refuse to learn Shell. My co-workers who use shell don't talk to anyone and look like zombies. Hell no. I don't even know their names after working 2 months together. Fire me.10
-
Fun Fact: Did you know that git clone starts a child process for downloading the repo but the parent process terminates, therefore working in an asynchrone way so &&-ing the next instruction, which might rely on those files, won't help you?
Well now you know, and so do I.
Fornicating piece of excrement, what a fun afternoon.17 -
Earlier today I had a old schoolmate of mine PM me.. long time no see, yada yada, don't beat around the bush please... Turns out that he wanted to get a bot for OldSchool RuneScape and found a bot that was paid... And didn't want to shell out 70-odd shekels and wanted me to write a "private script". Looking at the program he linked, it looked like it'd easily take thousands of lines of code and well over half a year to reimplement.
I'm sure that it's a problem we've all had at some point, and with old friends it's especially hard to deal with. Would you give in to something that's obviously gonna be a trainwreck of a project? Tell them that they're an ass for even thinking of something crazy like this? It's not exactly hard to get offended by something like this, as if our time and expertise is worth absolutely nothing.
Honestly, I just told him.. this will take several months to implement. Here's another project I wrote (https://git.ghnou.su/ghnou/cv if you're interested) and looking at the commit log, you can see that I started it half a year ago, and more or less finished the project 3 months later. That project took ~100 lines of code and this project would easily take thousands, and months if not over a year of work. It's easy to see that it's unreasonable. Now he's going to get a project that's behind Patreon instead, after I told him that it's completely reasonable to ask money for a project like this. What's more, when private it would cost a hell of a lot more - my time isn't free.
Long story short, just honestly explain that so and so is why it's unreasonable, and this and that are other more viable solutions because such and so. Non-technical people aren't necessarily unreasonable because they're dicks, most of the time it's just ignorance. Nothing wrong with that, and mistakes happen to the best of us :)3 -
This snippet was found in Thanos’ bash history:
```
ps Sh | sort -R | awk 'NR % 2 {print $1}' | xargs sudo kill -9
```joke/meme shell script thanosdidnothingwrong avengers joke marvel scripting snaps that hurt in prod thanos bash -
Bash is a ridiculous language.
Imagine if a the default shell language was quick and easy (like Python) how much quicker you'd be able to whip up a script - or even debug it.
And to all the bash lovers, no I don’t care about the history of the stupid language and don't try and convince me you whip up a quick script in 2 minutes.36 -
Since the past 7 months I was working on a project coded in C++ and shell script.
Today I was shifted to a project where I'm required to code in JavaScript and SQL.
I can't differentiate between my head and a scrambled egg.6 -
Internship Company employee: Hey, we need 600 images uploaded to a wordpress site, you'll have to do that for me.
Me: Alrightyy, can you give me some FTP or SSH access or something?
Employee: Nope, not allowed to.
Me: Uhm, I could write a shell script and run it?
Employee: The server is windows....
Me: Mother of god, I'll have to do it manually then?
Employee: You could ask John (my technical guider, not his real name) if you can borrow some fellow interns!
Me: *walks to John* Hey man, can I borrow some interns?
John: What for?
Me: Manually uploading 600 images to posts :).
Interns: *looking at me with a deadly view*
John: Sure!
Interns:3 -
Fuck android studio updates, fuck OpenGL libraries, fuck nvidia graphics on Linux, fuck it all to hell.
These bullshit updates keep breaking stuff in apps, and then the emulator itself gets broken somehow, then I need to run a bullshit shell script I found on some esoteric Arch Linux forum to symlink OpenGL .so libraries on my Linux machine every time I update because fucking OpenGL and nvidia crappy drivers on Linux, which also broke my xrandr configs and segfaulted the xfce4-display app.
Seriously that's horseshit. Linux will never ever ever break through the glass ceiling and become idiot-proof non-tech user friendly like the botnets Winblows and macPrison.6 -
It all started with a simple shell script that ran a bunch of build commands.
Then it became a python script that ran a bunch of build commands because why not?
Now it's becoming an electron app with a jazzy UI.. that runs a bunch of build commands. Because why not! -
I can't explain why, but I really like writing small tools in shell script.
Its so simple but so powerful.7 -
- build a self-service shell script to manage your environment in all kinds of ways with a single script and different switches
- ask tech manager for a server to keep that script [and others] at so coleagues should not bother setting dependencies up on their windows workstations
- be asked to list out all use cases
- be promissed your consolidated tool will be torn apart and replaced by 8 other tools depending on use-cases. Meaning 8 different browser windows open at all times to manage your single env
- be assured that this kind of improvement will take months and is doubtful to pay off2 -
That absolutely glorious fucking moment when you have to pay >1'000 bucks a semester and STILL have to shell out 15 goddamn bucks to print out a motherfucking script. That's like 2 beers!9
-
Dear God,
Not a single time in my life I was able to correctly spell "sudo" on the first shot: I always get "sudp" first. Am I praying the wrong prayers?8 -
I fucking hate the process of setting up IDEs and compilers! All the build files, cmake files, tasks, all that shit.
I undrerstand it's integral part of coding, but fuck, why does it always take so long to set up a stupid project. Just let me start coding ffs.
Sometimes I get so frustrated that I rather write a bash script or run the compiler commands in the shell instead of going through the hassle of setting all this up.2 -
My newest BASH project: reactive BASH
:)
Yes, I do like shell THAT much!
Since today my bhttp lib supports STOMP [still need to work on 1.2 compliance], i.e. I can carry out live communication with MQ. Meaning I can script the whole thing, be it 5 calls 5 reads, be it 20 subscriptions and reacting to unlimited number of messages in either of them with separate actions. WITHOUT A FOREST OF IF-ELSEs OR CASE-ESACs!!!
Boi do I love shell scripting... :D
Next project: AI in BASH3 -
How it started:
Need to replace in a lot of SQL files certain stuff...
find . -type f -iname '*.sql' -exec sed -i 's|new|old|g' {} \;
12 hours later that find executed a shell script containing roughly 120 lines of text pipelining.
The jolly of inconsistent workflows.
Different SQL format stylings... Makes fun when single line string replace needs to be extended to multiline RegEx handling. Or matching SQL comment configuration..
Different line endings. MacOS, Windows, Unix, Bukkake.
Different charsets / collations. Anyone wants latin1_swedish_ci... utf8... utf16... :/
Realizing some people even left sensitive data inside the SQL files (e.g. API Tokens..... Yayyyyyyy).
...
Ugh. It's never a one liner. It's never easy. -.-
I hate cleaning up messy shit.3 -
I have multiple contenders ;)
Contender one:
A program used to sort emails.
We was in the process of moving from lotus notes to exchange and needed a way route emails to the right server internally.
Solution, a qmail to receive all emails, a script running by cron every minute to read the emails, check the recipient name to a list and resending to the right server. The script was written in php :P since that was the only way we at the time had to read an email into an object, it was run just like any other shell script :D
Contender two:
A multi threaded mail sender that fetch email addresses and content from a database and posted them through qmail using background execution and pipes to get the result back and then update the database, written in bash script.
Contender three:
A c program used in a similar way as in one but this time using dial up and uucp to fetch email and then drop these either into lotus notes or into a bbs for our customers to give them an email address. This was around 1993, so not to many isp’s offered email and not to many had internet anyway, dial up bbs was much more common.5 -
I am scratching my head since 2 days cause a rather large Dockerfile doesn't work as expected.
CMD Execution just leads to "File not found".
Thanks, that's as useless as one ply toilet paper...
Whoever wrote the Dockerfile (not me…) should get an oscar...
Even in diarrhea after eating the good one day old extra hot china takeout from dubious sources I couldn't produce such a dumpster fire of bullshit.
The worst: The author thought layering helps - except it doesn't really, as it's a giant file with roughly 14 layers If I count correctly.
I just found out the problem...
The author thought it would be great to add the source files of the node project that should be built as a volume to docker... Which would work I guess....
Except that the author is a clueless chimp who thought at the same time seemingly that folder organization means to just pour everything into one folder....
Yeah. That fucker just shoved everything into one folder.
Yeeeeeesssssssss.
It looks like this:
source
docker-compose.mounts.yml
docker-compose.services.yml
docker-compose.yml
Dockerfile-development
Dockerfile-production
Dockerfile
several bash scripts
several TS / JS / config files
...
If you read the above.... Yes.
He went so far to copy the large Dockerfile 3 times to add development and production specific overrides.
I can only repeat what I said many times before: If you don't like doing stuff, ask for fucking help you moron.
-.-
*gooozfraba*
Anyways...
He directly mounts this source directory as a volume.
And then executes a shell script from this directory...
And before that shit was copied in the large gooozfraba Dockerfile into the volume.
Yeeeaaah.
We copy stuff inside the container, then we just mount on start the whole folder and overwrite the copied stuff.
*rolls eyes* which is completely obvious in this pit latrine of YML fuckery called Dockerfile.
As soon as I moved the start script outside the folder and don't have it running inside the folder that is mounted via volume, everything works.
Yeah.... Maybe one should seperate deployment from source files, runtime related stuff from build stuff.
*rolls eyes*
I really hate Docker sometimes. This is stuff that breaks easily for reasons, but you cannot see it unless you really grind your teeth and start manually tracing and debugging what the frigging fuck the maniac called author produced.1 -
OMG... this client is killing me...
So they are writing a Java / SpringBoot app for whatever. For some reason they decided to write it in the overcomplicated way, i.e. using a custom Spring's BeanPostProcessor that changes the eventual type of some beans, causing some weird ass issues, causing the app to fail to boot up if built on some systems and start up just fine if built on others (https://stackoverflow.com/questions...).
I've advised the client (devs) to simplify the architecture and avoid using type-mutating BPPs (bcz.. you know.. noone does that..).
Instead, the client created a task for me to "remove the build logic creating JAR packages" and another "Create a shell script manually assembling the CLASSPATH list and launching the application"
omg... what the hell is going on? Am I on camera? This can't be real... in 202-fucking-4 in a greenfield project!!!
wtf...1 -
Our teacher who teaches us Linux doesn't even know how to run shell script. Every time we ran into the problem he is like you should solve by it yourself. Most of his lectures seems nonsense to me and looks like I'm wasting my time and money7
-
So I was looking for a way to easily take android screenshots in a lossless image format, since my OEM only does jpeg.
Didn't want to install another adware and wound up with the adb shell screencap command since I need the pictures on my PC anyways.
But instead of a nice one-liner like
adb shell screencap -p > screenshot.png
I need 3 lines in a bash script.
Can we please just end the line ending wars?5 -
Any individual project that made me learn cool stuff...
Maybe the kernelcheck project? It's a shell script that I wrote 2 years ago (it's still on my GitHub but the code looks kinda horrible tbh), and it really made me respect the stability of package managers, and the effort that package maintainers must put into it. Even a single package (the kernel) that you have to maintain the integrity of the .config for (the configuration file that tells you what options to compile in, as a module, or not at all) while on every new minor release, the config changes ever so slightly.. at some point I figured that I'd really need to do those compilations manually, to be able to supervise (and if necessary adjust) it in real-time. The ability for distribution maintainers to do this for thousands of packages.. it boggles my mind. Respect! -
Today I created my first shell script for automation.
I have a git repository I use for backing up documents at the training centre I'm at for work. Not a specific project, just all of the documents and miscellaneous stuff. The need for this came about because they re-image the computers every month with a new version of windows (Because they're too cheap to register windows). And I can't risk forgetting to copy all the files onto my USB drive the day before they re-image.
So at the end of each day I open a git bash and type:
git add .
git commit -m "Backup - dd/mm/yy"
git push
Not a particularly laborious task but repetitive and time consuming.
So I decided to create a .sh script to automate the process
(The idea originally occurred because of this post: https://devrant.com/rants/329221/...)
So after about half an hour fiddling about with dates and $ signs, I came up with GitBackup.sh:
git add .
today=$(date '+%d-%m-%y')
commitMsg="Backup - "$today
git commit -m "$commitMsg"
git push origin master
Not much but proud to call it my first automation script.2 -
That moment when every line of your shell script runs perfectly when executed individually. But complete script doesn't.
-
How would you go about writing ES6 in your node applications? I'm using nodemon together with babel-core/register and then using a shell script on my server to build it.10
-
Once I wrote a shell script to solve a problem. Then I thought "now I have to rewrite it in a REAL language". So I did it in Go. But then I got bored and left it to rot in my gh. I picked it up again today and made another rewrite, but now in node. What the actual fuck4
-
Spent over an hour on a shell script that wasn't working properly. I use it, works perfectly. Every time cron executes, does nothing, not even log an error.
It took me that long to realize that the user I was getting the cron to run on didn't have permission to write to my log file... You would think I'd realize this when my error scripts didn't log...
(on that note, the Bandit games at OverTheWire have been awesome refresher on getting back into the swing of linux - highly recommend) -
I am programming a site where developers can share shell scripts and other users can execute it via a CLI.
I decided to add a little joke into it: the page where users can view a shell script is https://mukodik.com/scriptid.sh
I use Express, so I just use app.get('/:id.sh') to get the scriptid.
How would someone possibly bug out this page? (the uploaded shell script is not actually stored in a file, it's stored in a mysql database(using connection.escape to escape chars))2 -
How did I end up looking how to write asynchronous function in shell script whereas my task is to write a distributed chat app in Node.JS ?
Damn this is going to be complicated. -
Well it's nothing I wrote myself but I don't know why it exists.
I currently work on a reasonably big LaTeX (markup/typesetting) project.
For what ever reason someone had the glorious idea to build a Compiler in Java to compile the LaTeX sources to PDF, so far so good.
The problem is that
1. Most people working on that project either use an editor with its own compiling functionality or
2. use the shell script in the same fucking directory
Of course the Compiler is also slower than both of the above and tends to crash.
Well at least it's not my time which went into there. -
Started working with the Fish Shell, liked it pretty much until I had to write a shell script!! Things are so different from bash/zsh. Now i need to learn how you do things in fish.
Fuck you Fish!!:/7 -
Two (2) senior developers and one (1) senior tester left our team and I am left with two (2) Java legacy applications that are hard to maintain. Here is a list of things I hate about these old webapps (let's call them app A and B):
1. App A depends on 80% web services. If one web service for a product or warehouse goes down, work flow is impeded while prod support team checks with the core services team for repair
2. App B is a maven project with multiple modules dependent on libraries that are dependent on company's internal libraries. So if we want to upgrade to OpenJdk 9 and up, the project will definitely produce a lot of errors due to deprecated/unsupported codes
3. App A is dependent on Tibco and I have no experience on that
4. App B's continuous integration build tool is Jenkins and the jobs that build it has a shell script that wasn't updated during the tech upgrade enhancement. The previous developer who did the knowledge transfer to me didn't tell me about this (it should be considered a defect on her part but she already resigned)
5. App A when loaded in eclipse IDE is a pain to work with since it is only allowed to build a war file using ant. I have to lookup in quick search instead of calling shortcuts (call hierarchy) because the project wasn't compiled via eclipse.
6. It's impossible to debug app A because of #5
7. Both applications have high priority and complex enhancements and I have no other teammates to help me
8. You never know what else can go wrong anytime1 -
due to some error on GCP, my and friend got locked out of a prod server over ssh.
And the fucking admin was not giving us privileges to do it through serial port, why you ask cause submitting keys from dashboard was not working.
Later, found out google runs a startup script from startup-script metadata tag.
It felt like showing a middle finger to the admin and google -
Fuck python
I have no experience in python and barely any in anything else and I want more than anything to learn this fucking language, but I cant launch the simplest fucking script in the world ("hello world.py") without getting a syntax error, not with my code, but with the fucking path which I checked and rechecked a million fucking times. I remember coding in shitty-ass Java using jGrasp for a year in college, and it was fantastic, but sitting here trying to sort out a fucking script in the IDLE shell is making me want to jump off the 10th fucking story. Kill me, please. I tried running in Atom text editor using the "Script" package, but that would have been too fucking convenient. I just keep getting errors and a fucking hourglass next to the name of my code at the bottom of the window, fuck me5 -
Good: local news website has an interactive news paper online
Bad: You have to pay for it
Good: Found the exposed URL to all of the paper images
Bad: can't download from its parent directory
Good: made a shell script to download all images4 -
So for the past one month I'm working on an enhancement in a product coded in C++ and shell script, running on RHEL. After toiling away for almost 10 hours/day for a month, the enhacement is ready. Coded, tested, documented. Ready to ship.
The client is supposed to recieve the update as a drop. 1 day before the drop is scheduled to be released to Quality Control, I fire an overnight build on the build machine, update the change request ticket, update other related tickets, inform QC of the drop to be released tomorrow. On the D-day, I package the drop using the company's painfully arduous method. Everything is ready by the evening, and the drop is good to go.
At 7pm (one hour before the drop is to be released), Jack fucking Jack-o-lantern (one of the top most exec in the company) tells me that the default value of the parameter introduced in the enhancement, needs to be changed from 86400 to 1500. HALF AN HOUR BEFORE THE DROP IS TO BE RELAEASED!
Now here I am, changing the value in over 25 files, followed by firing an overnight build, followed by sanity testing, change specific testing, followed by drop packaging, followed by inform QC that the drop will be delayed.
All because fucking jack-o-lantern wanted to change the fucking default value.
GOOD FOR YOU FUCKING JACK.2 -
Sometimes, I feel like tearing my hair out from the way Bash works.
Like... Where other languages have two operators for case-sensitive and insensitive regex matching, bash? It doesn't. It only matches case-sensitively.
And if one wants the insensitive matching? Gotta set a shell option... And if a script wouldn't change it back, who knows what else could break, so of course it has to save its initial state, change it, do its case-insensitive matching, and return it back to its original value.
10/10 experience.14 -
Just a quick follow up. I told you guys after rebooting my server by accident, I'll color in the terminals for my ssh connections.
Normal terminal in white. With the code to do it. Just a shell script with the name ssh earlier in the path than the actual ssh. That was the only solution that didn't fuck my auto-completion. compdef was somehow useless. But it is simple.
For some reason I had to hardcode the return color to white. Alacritty was not happy with just a no-color code. But whatever. Super useful. I won't accidentally restart non-host computers now.
Planning on extending this to have different colors according to the host. Like my homelab could be green. Live servers would be red. Dev servers blue. But that's for the future.
Just wanted to share my little improvement that will make my computing saver.8 -
My work product: Or why I learned to get twitchy around Java...
I maintain a Java based test system, that tests a raster image processor. The client is a Java swing project that contains CORBA bindings to the internal API of the raster image processor. It also has custom written UI elements and duplicated functionality that became available in later versions of Java, but because some of the third party tools we use don't work with later versions of Java for some reason, it's not possible to upgrade Java to gain things as simple as recursive directory deletion, yes the version of Java we have to use does not support something as simple as that and custom code had to be written to support it.
Because of the requirement to build the API bindings along with the client the whole application must be built with the raster image processor build chain, which is a heavily customised jam build system. So an ant task calls out to execute a jam task and jam does about 90% of the heavy lifting.
In addition to the Java code there's code for interpreting PostScript files, as these can be used to alter the behaviour of the raster image processor during testing.
As if that weren't enough, there's a beanshell interface to allow users to script the test system, but none of the users know Java well enough to feel confident writing interpreted Java scripts (and that's too close to JavaScript for my comfort). I once tried swapping this out for the Rhino JavaScript interpreter and got all the verbal support in the world but no developer time to design an API that'd work for all the departments.
The server isn't much better though. It's a tomcat based application that was written by someone who had never built a tomcat application before, or any web application for that matter and uses raw SQL strings instead of an orm, it doesn't use MVC in any way, and insane amount of functionality is dumped into the jsp files.
It too interacts with a raster image processor to create difference masks of the output, running PostScript as needed. It spawns off multiple threads and can spend days processing hundreds of gigabytes of image output (depending on the size of the tests).
We're stuck on Tomcat seven because we can't upgrade beyond Java 6, which brings a whole manner of security issues, but that eager little Java updated will break the tool chain if it gets its way.
Between these two components we have the Java RMI server (sometimes) working to help generate image data on the client side before all images are pulled across a UNC network path onto the server that processes test jobs (in PDF format), by reading into the xref table of said PDF, finding the embedded image data (for our server consumed test files are just flate encoded TIFF files wrapped around just enough PDF to make them valid) and uses a tool to create a difference mask of two images.
This tool is very error prone, it can't difference images of different sizes, colour spaces, orientations or pixel depths, but it's the best we have.
The tool is installed in both the client and server if the client can generate images it'll query from the server which ones it needs to and if it can't the server will use the tool itself.
Our shells have custom profiles for linking to a whole manner of third party tools and libraries, including a link to visual studio 2005 (more indirectly related build dependencies), the whole profile has to ensure that absolutely no operating system pollution gets into the shell, most of our apps are installed in our home directories and we have to ensure our paths are correct for every single application we add.
And... Fucking and!
Most of the tools are stored as source bundles in a version control system... Not got or mercurial, not perforce or svn, not even CVS... They use a custom built version control system that is built on top of RCS, it keeps a central database of locked files (using soft and hard locks along with write protecting the files in the file system) to ensure users can't get merge conflicts by preventing other users from writing to the files at all.
Branching is heavy weight and can take the best part of a day to create a new branch and populate the history.
Gathering the tools alone to build the Dev environment to build my project takes the best part of a week.
What should be a joy come hardware refresh year becomes a curse ("Well fuck, now I loose a week spending it setting up the Dev environment on ANOTHER machine").
Needless to say, I enjoy NOT working with Java. A lot of this isn't Javas fault, but there's a lot of things that Java (specifically the Java 6 version we're stuck on) does not make easy.
This is why I prefer to build my web apps in python or node, hell, I'd even take Lua... Just... Compiling web pages into executable Java classes, why? I mean I understand the implementation of how this happens, but why did my predecessor have to choose this? Why?2 -
I made a php script to generate a powershell script that performs asset conversion. The conversion tool was designed to work via command prompt but i hate using it so i switched it up to powershell and after that i had to build a powershell script because running the shell exec function failed miserably, sad part is that just about to the end of the conversion, that ran in the background for a little over 2 days, i ran out of disk space so it stopped doing anything :( w/e i at least got what i was interested in.
-
Not the biggest hurdle, but I felt like THE BOSS on finishing the task.
I have to create Branch in a repository for respective folders in S3 bucket and have to commit that folder into it's respective branch. There are around 29 folders in the bucket, the task would have taken my entire day. Rather I completed the task in less than half an hour. Shell Script is the coolest tool, which saved my entire day, indeed I felt like THE BOSS. -
So a mate gave me a server to sue for my minecraft server for free rather than paying...
Me being the smart lad that I am made a simple shell script to make some tasks easier but decided to add the rmw and rcw arguments to delete the world and re-create the world respectively...
I feel like you all know what I did...
(Side note, going to be hosting a bedrock edition one as well if anyone may be interested?)3 -
How do you do bootstrapping of blanko machines?
Imagine you get a linux/BSD/osx machine and you want it set it up to a defined state to be prepared for further setup.
Like users
ssh config
Sudoers file
Config management client or credentials
Software like vim, htop and tmux
A simple shell script sounds a bit archaic to me and i was wondering, if there is a better way...
Makefiles also came to my mind but still... Unsatisfactual4 -
Duck! this sloppy whiny winnfsd.
Yay! Let's use state of the art Docker with a VirtualBox VM on Windows10.
Don't get me wrong.
The Docker containers in this VM doing a great job on performance.
But in the very moment a Docker container uses a mounted folder via the windows network filesystem, all hell is breaking loose.
Building a vendor folder using a composer Docker image with 84 Packages takes about 15 seconds when cache has been warmed up.
The same Docker command pointing on a folder mounted to Windows Filesystem with warmed up cache takes about 10 Minutes!@&&@""+&
And what is the duckin' reason for this delay?
Because every transfer of a teeny tiny file has to establish a connection to fat ass Windows OS and has to pass it's glorious "security" layer.
DUCK it!
For real.
I currently working on a shell script which builds the whole vendor folder on a volume on Docker VM.
After completion, the shell script will compress the folder to one file.
This one file will be transferred over this god damned network filesystem.
Finally the script will unpack the compressed vendor folder in it's destination folder.
*sigh*
What year is it?!??3 -
"hey, write us a simple interface for this shell script.."
script:
- input must be a file, does not accept loading through stdin/redirect
- accepts relative path input from one specific directory only
- fails if provided absolute path
- even though it fails, it still returns return code 0
and every time we've tried to open up a topic of programming practices we got slammed with "we're ops. you should be glad they're doing at least some scripting"5 -
A cool bash shell script to download (cut) a portion of video from youtube. It depends on youtube-dl and avconv/ffmpeg tools which can be installed from the distribution.
Bash Shell Script (can be named as ytcut):
Note: No error handing implemented
#!/bin/bash
#set -x
_yt_id="$1"
_yt_start_time="$2"
_yt_end_time="$3"
#_yt_format_id="bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio"
# use youtube-dl -F <video id> to get the list of formats available
# Using format id as 22 as the above one didn't work.
_yt_format_id=22
_yt_time_selection_opts="-ss ${_yt_start_time}"
_yt_time_selection_opts="${_yt_time_selection_opts} -to ${_yt_end_time}"
_yt_url=$(youtube-dl -f ${_yt_format_id} -g "${_yt_id}")
_yt_filename=$(youtube-dl --get-filename --restrict-filenames -f ${_yt_format_id} "${_yt_id}")
avconv -y -nostats -loglevel 0 -i "${_yt_url}" ${_yt_time_selection_opts} -codec copy "file:${_yt_filename}"
Example Usage:
ytcut 3dWrKNrWbWQ 0:40 1:402 -
Q: Is there a software which can record my keystrokes and clicks and then translate that into a Power shell or Python or any script?6
-
So, I have a pretty decent understanding of big complete languages like Java, I build android applications following several design patterns, solid principles, building big stuff with databases and servers and libraries interconnected with gradle, tracking everything with git, using tdd and functional programming capabilities blablabla ... And I still have trouble making sense of a FREAKING STUPID SHELL SCRIPT I MEAN WHO CAME UP WITH THAT SINTAX I HATE IT SO MUCH OMG I CAN'T EVEN
But for real everytime I need to read a '.sh' I literally wanna throw my computer away and die. Am I alone? -
Well, that is a record. 11 minutes into work and I already want to choke slam whoever wrote this shell script. I am looking for someone older than dirt because they used ` ` instead of $(). And now I am going to have to change group GIDs for 3 groups times 500 machines. They all need to match and are ALL different. FML
-
When I first joined my company as a fresher, and learnt Shell, someone suggested me to write a script, which would be useful to me as well as help me learn, that would pull code from all the projects that the company has.
Today, the other fresher, asked me for it (he learnt shell after me)... So I shared it on github. I know its kinda stupid :P
https://github.com/AseedUsmani/...
Reviews?2 -
Shell scripting is one big fucking pain in the ass !
Why the fuck is it so syntax sensetive!!
Cant you even fucking consider a space between a variable and a operator by yourself ?1 -
When you create some shell scripts on the servers which are supposed to mail your team each day at 9pm and you leave for vacation at 4pm only to see the emails suddenly arriving on the way home at 4:30 telling you and everybody else that almost everything possible went wrong on an unknown server.
-
Found this in a shell script. Instead of just one regex, why not use grep and sed, even though you could have just done it all with sed!
IMAGE_TAG=`grep defproject project.clj | sed -e 's/^.* \"//' -e 's/\"//'`2 -
I wasn’t able to run a bash script right now using ./script.sh as I was getting an error “Command not found.” I tried running it using source command instead of ./ and it worked! What’s going on here?9
-
Is anyone good with writing shell scripts here?
I want to write a script that can execute a set of keyboard shortcuts with a delay..9 -
I was setting up a CI build machine. Builds were supposed to be ran in disposable containers, but I needed a way to trigger a task on the host from inside the container. I didn't want to give containers shell access to host - kinda misses the point.
Solution: a server running on the host and listening for predefined commands on a named pipe. The pipe was bound into containers which would simply echo commands into it. Very simple and effective.
The hacky part? The server was an 8-line bash script.1 -
Learning power shell for a "shutdown in X hours"-script and windows batch for scripts to start all my games that might need to auto-update, so I could start the next session faster and one to start all games with daily login rewards.1
-
The little things are what makes you happy.
It was really annoying that screen doesn't work after an su. It makes sense, but typing "script /dev/null" everytime (and remember to write "exit" after it so bash history works again) is annoying.
So a little script to "/bin/scrn" with the following content made my life better:
#!/bin/sh
command="screen $@"
script /dev/null -c "$command"
Never worry about screen after su again! Tech life is great, isn't it?4 -
So this is more like an accident rather than a dissapointment but the thing goes like this.
I make multivariant stacks with vagrant, shell script loaded as stated in yaml config and every bit and piece done from there the only times it disapointed me was the first time i lost it and when i got asked to make it tomcat compatible, not that the person really needed tomcat but just because i called it a stack initialiser it must have tomcat support. -
That moment your shell script works after hours of debugging.
Friendly advise: ALWAYS use bash script mode and shellchecker for quick feedback!1 -
TIL RVM and I are on different assumptions. I'm talking about RVM allowing unbound variables in its scripts.
I don't because I literally have run "rm -rf /" on my Mac because of an unbound variable in the past. So, when I write a shell script, the second line is always "set -eu."
And because RVM allows unbound variables, this line crashes RVM.
Then for some stupidity on my part, I looked into GitHub for its codebase first to get even more clueless about the issue before finally googling to see if anyone had experienced the same problem 🤦1