I’m using Ubuntu and set postfix up to use gmail as a relay to send mail following this guide. I can send emails fine but I would like to receive emails and run a script like this. Is it possible to receive emails from my relay and then run a bash script? Answer We figured it out using fetchmail to
Tag: bash
Pass Telnet Command to SSH in Bash Script
I’m trying to write a bash to first ssh into a server and then telnet from that server to a ElastiCache Redis endpoint. My Code is the following: telnet.sh I would like to call my bash script and have the user interactively be connected to the Redis Cluster so that the user can enter redis cli commands …
Bash: if statement always succeeding
I have the following if statement to check if a service, newrelic-daemon in this case, is running… The problem is it’s always returning as true, i.e. “New Relic is already running”. Even though when I run the if condition separately… … it returns 0. I expect it to do nothin…
How to specify two variables on bash command line?
For example, I can do this: But how can I do this? I cannot use this: I have to do it in one line Answer As far as I know, every Bourne shell allows any number of name=value pairs preceding the command to establish the environment. Bash certainly does.
Finding emails from one file in another
I want to find emails from one file listed as such: in another file listed as so: and output the lines from the second file that match with the first file also keeping in mind it needs to match the entire email from start to finish so it won’t match robertjohn@blogs.com accidently. Desired output: Thank…
Quote a filename containing quotes and given as variable in Bash
Let’s say I have a directory path in variable DIR and I want to list this directory. If I care only about spaces in the path, then I could do What should I write if I want to support also single and double quotes and other weird stuff in the directory path? Example: Answer Quotes are not just for spaces
Bash sort -nu results in unexpected behaviour
A colleague of mine noticed some odd behaviour with the sort command today, and I was wondering if anyone knows if the output of this command is intentional or not? Given the file: We are looking to sort the file with numeric sort, and also make it unique, so we run: The output is: Now, we know that the numer…
AWK usage issue while archiving HDFS files in Hortonworks Distribution
I am trying to move files in a HDFS directory that are over 3 days old to an archiving folder in HDFS. AWK Script: Note: cmd variable would have a mv command once this script starts working Issue: Value of variable X is constant Value of Variable Y is constant Unable to get day difference between 2 date , i
Function to search of multiple patterns using grep
I want to make a bash script to use grep to search for lines which have multiple patterns (case-insensitive). I want to create a bash script which I can use as follows: and it should get traslated to: I tried following bash script, but it is not working: The error is: Answer I think you can do a recursive fun…
Faster solution to compare files in bash
file1: and file2: I need find match file2 in file1 and print whole file1 + second column of file2 So ouptut is: My solution is very slow in bash: I am prefer FASTER any bash or awk solution. Output can be modified, but need keep all the informations (order of column can be different). EDIT: Right now it looks…