As a beginner i’m looking for a solution in shell scripting, I have file1 with content as below lines: And file2 with filenames and their modified timestamp. I’m looking shell script solution where it can tell the closest match in timestamp in the between both files. Like timestamp_x and timestamp_y comes in between timestamp_1 and timestamp_2. Thanks Answer If your
Tag: shell
Bash script how to display matched words in custom order
The following is the output of the command ads2 cls create However, I’m trying to extract the value of name and state for each node, save them in a variable and display them in the following order: Till now i, with the help of this so much powerful learning site, could extract the values of name and state by executing
How to replace a hash pattern inside file and directory names (Linux)
I’ve just backed up the notes I have in Notion, and they use hashcodes in the notes names to make them unique apparently. For example, this is might be a note-folder with some notes: (Sometimes there’s also a .csv file for tables) I was trying to use a regex like [a-z0-9]{32} to replace the pattern, but was having difficulty making
Capturing output from a background subshell in bash?
I’m trying to run multiple subshells in a bash script and capture the stdout result to a variable. When I run the subshell in the background I would expect I can use wait to let the subshell complete and then use the variable the result is assigned to later in the program…. but it doesn’t seem to work. Simple example
Shell Script : MongoDB Dump
I’m creating a shell script to automatically dump the database. I have the current code below. The problem is when I’m opening the zip file it shows a single binary file. Usually, when I dump manually it consists of bson and json files. I don’t know what I’m doing wrong I’m expecting a zip file with bson and json file.
Sh script not running using cron while running using terminal manually
I have a script .sh that works when executed manually but not working through cron : There are other .sh which runs perfectly with cron. I don’t know why this one doesn’t work. I compared the env output from the terminal and from cron and both are similar beside the user which has higher privilege in cron using : The
Wait Until Previous Command Completes
I have written a bash script on my MacMini to execute anytime a file has completed downloading. After the file download is complete, the mac mounts my NAS, renames the file, and then copies the file from the mac to the NAS, deletes the file from the mac and then unmounts the NAS. My issue is, sometimes, the NAS takes
How to displays the owner privileges of the files in the current directory in linux os?
I want to displays the owner privileges of the files in the current directory For example the output like this : I’m trying to write this command , but the output is not correct : Answer You just do this command :
How to SSH a curl command
env = GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu) Situation: SystemA=No internet. SystemB=Yes internet. SystemA has a log file. SystemA wants SystemB to send a curl command for him. SystemA$ ssh SystemB curl -X POST -H “Content-type: application/json” -d “$data” $hook = fail SystemB$ curl -X POST -H “Content-type: application/json” -d “$data” $hook = success How do I achieve this without SystemA
Is there a program that functions like printf with an entire file as input?
My use case is as follows. file.txt First arg: %s Second %s arg, Third %s Run prog file.txt “one” “$(ls dir1/dir2)” “three” Resulting in First arg: one Second file1 file2 file3 arg, Third three I first thought to use sed but that inevitably runs into problems when bash substitutions get read as format characters like this sed s/%1/$VAR/g -> sed