Skip to content

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…

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…

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…