Skip to content

Tag: bash

mail -s waiting for CTRL+D in bash script

I have this bash script to check if an nfs share is mounted but its hanging on waiting for CTRL+D to be pressed for the mail part when I run it – how do I get around this? Answer This is what every command which reads standard input will do if you do not provide it with standard input from

Arguments mismatch using where IN clause in query

I have column in hive table like below Now I want to get the distinct values as a variable so I can use in another query. I have done like below when I do I get below error what the the mistake I am doing? What is the correct way of achieving my result? Note: I know I can use

Bash Scripting checking for home directories

I’m trying to create a script to check if user accounts have valid home directories. This is what i got at the moment: This works. I get the expected output which is the username of the account with an invalid home directory. eg. output However, I am unable to make it so that ONLY if there is no issues …

Live Linux grep script – only print positive results

I try to code a bash 4 (or sh, if that’s possible) script that does the following: 1st parameter: the path to the compressed modules to search, could be “.” 2nd the search pattern to look for The script so far looks like this (be aware that it is not foolproof, it not checks if both paramete…

Extra percent sign appears in echo bash

I’ve got the following script below which is supposed to demo CPU utilization: For some reason, when the percentage is echoed out, two percent signs appear instead of the last digit of the number and a percent sign. For example, the output is sometimes 2.7%% instead of 2.72%. Everything works fine when …

Fetching specific value from a variable in Bash

I have a variable which runs a specific bash command: The output of echo $Model can be as below: I want to grab only the value Model RZ230 I am using the following but it is not working: Using above command I am getting output as: `My output should be Answer Use Bash parameter expansion : Regards!

Bash Scripting – REGEX to dump a file list

I have 4 files extensions as result of previous works, stored in the $SEARCH array, as follows : I want to issue one file list for each of the 4 above extension patterns, as follows, except for the case with 2 dots and 2 extensions (marked “NO”) : Obviously I spent hours on regex101 w/o success. I…

Terminal closes when I source my script (run with dot at the start)

Here is my code: The problem is that when I start it like this or without argument, it just closes. I know that the reason for that is exit. Is there any way correct my code so I could start a script with dot at start and terminal wouldn’t close after execution? I don’t want to start it like this: