Running Ubuntu 18.04 subsystem on Windows 10, but have also tried to do this on a Ubuntu 18.04 Google cloud virtual machine. I’ve realised that baking my login credentials into my scripts is a rather dumb idea, not just for the security risks but because I’ll have to edit every script if I change …
Tag: bash
Delete logs that ended with date format
I created the following cli in order to delete the logs with date format that oldest then 500 min date format is: the cli that should removed the logs as we can see the logs still exists where I am wrong? Answer Your regex does not match the files. Change ‘.*.log.[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2,10}$&…
Exiting bash script without terminating ssh connection
I’m pretty new to bash scripting and I’m attempting to write a script that does some basic operations. I want to check certain conditions and if they are met, terminate the script. So for example, I want to check whether the zip of files was successful: What happens though is that the exit 1 signa…
BASH: Filter list of files by return value of another command
I have series of directories with (mostly) video files in them, say I create a variable (video_dir) with the directory names (based on other parameters) and use that with find to generate the basic list. I then filter based on another variable (video_type) for file types (because there is sometimes non-video …
How to create folders and files from paths given in text file
I have a text file named creating.txt. In this file, each line has a path. If line starts with D it means that I have to create directory. If line starts with F, I have to create a file. For example: I need to go line by line, first check if first letter is D or F, then ignore the
Find if a shell variable contains specific string and comment it
I want to write a script that looks for a variable and checks if it contains exact string and comment it if exists. I have tried using sed and grep but it hasnt worked for me yet. My script for deleting: JV_PAT contains the path were java in installed excluding the /bin JAVA_LOC = /data/jdk1.8.0_111/bin/java …
Is it possible to get command arguments now executing?
I want to declare aliases which append argument if no argument specified. For example, I expected executing vimtutor with no argument is replaced to vimtutor ja.utf-8, but it doesn’t work properly. So, I tried some tests on bash shell. And I understood it is impossible to get command arguments now executing i…
How to remove double quotes in a specific column by using sub() in AWK
My sample data is when I try to remove ” from colum 2 by It only remove only 1 comma, instead of b112122 i am getting b112122″ how to remove all ” in 2nd column Answer From the documentation: Search target, which is treated as a string, for the leftmost, longest substring matched by the regu…
Switch to root user within bash script
Im currently logged in as admin and I want to edit the /etc/hosts file which required root access. I’m not able to make the changes. The script gets executed sucessfully but the changes arent made. My Script – Runs Sucessfully when executed from terminal sudo -s – switches to root without pa…
Executing bash script via java in background after ssh connection is closed
I am using java to execute a simple bash script on a remote linux machine. The bash script named “shortoracle.bash” have this script: Simply speaking: create 10 parallel connection that execute queries for 360 seconds. From my java program i execute the following command: The ssh executes the scri…