I’m new to shell scripts, and I have centos running. I want to write a shell script that ssh a remote machine and execute a bunch of commands. The problem I’m facing is how to provide the username, the password, the remote machine address, and the private access key to a command that shall connect the remote machine. I’ve Google’d
Tag: bash
How to grep for a pattern in the files in tar archive without filling up disk space
I have a tar archive which is very big ~ 5GB. I want to grep for a pattern on all files (and also print the name of the file that has the pattern ) in the archive but do not want to fill up my disk space by extracting the archive. Anyway I can do that? I tried these, but
Run scripts remotely via SSH
I need to collect user information from 100 remote servers. We have public/private key infrastructure for authentication, and I have configured ssh-agent command to forward key, meaning i can login on any server without password prompt (auto login). Now I want to run a script on all server to collect user information (how many user account we have on all
Checking for installed packages and if not found install
I need to check for installed packages and if not installed install them. Example for RHEL, CentOS, Fedora: How do I do a check in BASH? Do I do something like? And what do I need to use for other distributions? apt-get? Answer Try the following code : or shorter : For debian likes : For archlinux :
Better bash script to create directory structure
I want to create folders with plain text with a structure like: I thought about using a base command like mkdir and found that post : Bash script that creates a directory structure, but it still needs to write structure like : So I would need to change the regex used in : What bash command could I use to
what does $* mean in a shell script
What does $* exactly mean in a shell script? For example consider the following code snippet Answer It means all the arguments passed to the script or function, split by word. It is usually wrong and should be replaced by “$@”, which separates the arguments properly.
Reading username and password from file
I’m looking at a away of reading the username and password of a file and inputing those to either add user or delete user. EG: I have a file named ‘userlist’ with the following content with this format: What I don’t understand completely is how to use BASH script to add these accounts. What I have so far is this:
How to check if sed has changed a file
I am trying to find a clever way to figure out if the file passed to sed has been altered successfully or not. Basically, I want to know if the file has been changed or not without having to look at the file modification date. The reason why I need this is because I need to do some extra stuff
check if argument is a valid date in bash shell
I am writing a bash shell script in Linux, this program will accept a date (mm-dd-yyyy) as a parameter. I am wondering if there is a simply way to check if the date is valid? is there an operator and I can just use test to check? Answer You can check with date -d “datestring” So date -d “12/31/2012” is
how to grep listening on port 80 that can also filter other port contain 80 such as 8080 8088 …?
I want to use bash to grep if any process is listening on port 80,but now I stumble upon other port number which annoys me. How can I filter this in grep? It also outputs other records such as 8080 8088 and so on. Answer I’m looking at the output of my netstat command, and see this: I take it