Skip to content

Tag: bash

How to implement a process overseeing another process?

Currently at my workplace I have a script named “batch launcher” (written in bash), which is supposed to oversee the execution of batches, logging their output and processing the return code of the batch. This is currently done via env call within this “batch launcher”: Several days ag…

Print a certain line in linux or options for nslookup

I’m very new to linux and bash. I’m trying to find a domain name for an ip address. When I use nslookup I have a bunch of lines like this Output I only want to print www.computerhope.com in the second line. How do I do this? Also I tried to use host command as well. It looks cleaner. How do

Does Bash ignore # after command?

I know that Bash ignores the # character at the beginning of shell script lines. But in documentation I’d like to add them at the end of lines for documentation: Just in case somebody copies and pastes the literal information I’ve written, will Bash ignore everything after the # character? For eve…

Converting date format in bash

I have similar different file of the format backup_2016-26-10_16-30-00 is it possible to rename using bash script to backup_26-10-2016_16:30:00 for all files. Kindly suggest some method to fix this. Original file: backup_2016-30-10_12-00-00 Expected output: backup_30-10-2016_12:00:00 Answer To perform only th…

bash if elif statement always prints first value

For some reason, the first value is always printed. I can’t figure out the reason behind it. Any ideas? I tried many things including single =, single [] but nothing seems to be working at all. Answer You need to add whitespace to the conditions:

Move all files at one level up one level

I had a problem with a backup on a linux server that somehow moved all folders of files down one level into a new folder with the same name. I would like to return all files to their original location. Many of the files have spaces in their names to complicate things. Original directory structure: Incorrect d…

Invoking subshells from script does not work if run in background

I have a script running in background, like: Now this script, invokeTest.sh has contents: Although it prints, “Hello World from invokeTest” it does not call test.sh. My question: Is there any way to call test.sh in infinite while loop directly from su – insite1 -c” “so that we ca…

read -a not working as expected in Bash

For some reason when using “read -a” my script is only taking the first element of the line into the array. For example, when inputting a string such as “canada China”, the output of the program simply reads: Instead of: The instructions for my assignment are as follows: Create a scrip…

Extract part of string in Bash

When I import my GPG keys, I get a response back: I would very much like to extract the key’s ID LOL12345. The command I run that returns the output is as follows: Answer Try to use grep: -P use perl regex style. -o print only the matched part. -m 1 exit after the first match. This will ensure, that