Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [bash]

Bash is the Bourne Again SHell, the successor to the classic Unix sh (shell).

0
votes
1answer
13 views

SSH PEM_PATH check for password prompt

I am copying the public key of the pem file generated from External Box to all EC2 instances. This prompts for password for first time Therafter I am able to do scp to all EC2 instance without ...
0
votes
0answers
18 views

shell script to backup folders older than 5 days [on hold]

I'm new to shell scripting... I need a script to backup log folders older than 5 days on a Ubuntu 14.04 Server, using 7z and tar. At present, I am using the below command to back it up one by one: ...
0
votes
1answer
35 views

How to start a jar file using systemd

I want to start java application on system boot using systemd. I tried to do by adding above scripts. But service is not starting. my-startup.service [Unit] Description=Startup [Service] ExecStart=...
2
votes
1answer
42 views

How to setup a cron job every random weekday?

As the question is fairly self-explanatory, I would like to know how to set a cronjob to execute any random weekday without using any external script. EDIT: In case people have not understood this ...
0
votes
1answer
29 views

Forward mail using qmail to multiple recipients dynamically

I am trying to forward an incoming mail to multiple recipients. The recipient's addresses are stored inside a mysql database, so I need to call a script to get the addresses before forwarding the mail....
0
votes
1answer
22 views

-bash: fork: Cannot allocate memory on remote server

I have the great -bash: fork: Cannot allocate memory error. Normall I would reboot. But that is not an option. Using only SSH can you imagine some trick I can use? /sbin/shutdown -r now gives the ...
0
votes
0answers
32 views

“Conversion” of the script from bash to powershell [on hold]

Unsure if it is appropriate community, but the question is diffuse between Linux and Windows... Using WSL and native Linux with installed adtool I love to perform routine tasks at Windows ADDS. One ...
-2
votes
0answers
20 views

ulimit not working with -f

I am trying to use ulimit to prevent my shell from writing to any files. The result is that I am still able to write the file. What I am doing wrong? $ ulimit -f unlimited $ ulimit -f 0 $ ulimit -f ...
0
votes
0answers
5 views

How Not To Bash Auto Complete File Name From the Beginning Letter? [migrated]

Say I'm in a directory and have a file called 01_test.py and if there are too many files in the folder and I forget the beginning of the file name and only remember there is a test in the file name, ...
1
vote
1answer
46 views

shell script to list directories in decreasing order of disk usage

I am looking for a shell script for Ubuntu Server that lists the disk usage of directories in a decreasing order. It should not list subfolders (recursively). The behaviour should be similar to the ...
1
vote
1answer
12 views

save hdf5 data when admin kills script

I have a lot of Monte-Carlo data that I need to process at a particular cluster. What I do is, for a given data sample (which is on average of size 70 GB), I run some statistics script in python on ...
0
votes
1answer
22 views

NFS Migration automation (CentOS 5)

I need a little help with an upcoming migration. The storage team has implemented a new netapp stack. Once I have a tested script, I have around 400 servers across two environments that I'll need to ...
0
votes
0answers
39 views

Run none Linux command in shell script

I am running the following code to telnet to a server via a shell script. #!/bin/sh (echo myusername; echo mypassword ; cat) | telnet -l myusername 127.0.0.1 After successful login, my shell changes ...
0
votes
2answers
14 views

automate settings change on multiple power appliances

I'm trying to automate the task of changing settings on 100+ power appliances via SSH but each settings change has multiple interactive prompts. Is this possible or does anyone have an example of how ...
-5
votes
2answers
60 views

chain two commands once the first one is finished [closed]

I want that once the decompression is finished the .tgz is erased I am trying with this: tar -zxvf glftpd-LNX-2.08_1.1.0g_x64.tgz $$ rm -rf glftpdLNX-2.08_1.1.0g_x64.tgz
-4
votes
1answer
47 views

Rename and replace parts with different filenames [closed]

I know there are different questions about this topic but I have found nothing that fits my question: I want to replace a part of a name in a folder but there are different files with different names....
0
votes
0answers
30 views

Merge two JSON strings with jq

I've been banging my head against the wall with this one a little bit, partially because I'm new to jq. I have JSON output from one command (terraform output -json). I want to take this data, rename ...
1
vote
1answer
33 views

How do I use Nagios to monitor a log file that generates a random ID

This the log file that I want to monitor: /test/James-2018-11-16_15215125111115-16.15.41.111-appserver0.log I want Nagios to read it this log file so I can monitor a specific string. The issue is ...
-3
votes
1answer
44 views

searching file for last matching line, then put 3rd word of this line into a variable

i have a logfile, a script checks this log-file every hour it shall pack the 3rd word of the last matching line into a variable but i didn't manage it to work yet .. logfile: 2018-11-18 22:27:10 ...
0
votes
0answers
14 views

Changing PF rules on the fly to mitigate damage of DDoS (OpenBSD 6.4) [closed]

This is a two part question, really. Keep in mind that I am a developer not a system admin, but being the only employee in the company, I wear ALL the hats. I have deployed my server with two ...
0
votes
2answers
55 views

Enough memory but OOM killer invoked?

It has been a long time since my old friend the OOM killer came to visit me. Now it is coming by once a week and I cannot figure out why it’s triggered. It doesn’t seem that I’m missing memory. What ...
0
votes
0answers
56 views

How to log all Bash (busybox/ash) commands by all users on a server?

How can we locally log all Bash commands run, along with user and time stamp? I am looking for a way to customize Ash sessions with my own sets of aliases and whatnots. What is the Ash equivalent of ...
0
votes
0answers
25 views

Get errors from Tomcat log in real time

I need to make a script to get certain errors from Tomcat log or maybe get them before Tomcat prints the erros to catalina.out. After getting error X, Y or Z, I want it to run a certain command, like ...
2
votes
0answers
78 views

How to get PCI Tx/Rx byte counters?

I know how to read statistics about the configured network interfaces, for example via cat /proc/net/dev. Is there a way to read similar byte counters of PCI or PCIe traffic? Apparently, according ...
1
vote
1answer
46 views

Crontab influences bash script if condition?

I am a bit baffled here, and not really sure how to debug this. I have a self-written bash script, that checks if a samba share is active, and if not, sends me an email. Script is in /root/SKRIPTS/, ...
1
vote
0answers
37 views

Create a screen. Run said screen as a user. Detach

I'm essentially trying to combo Create screen and run command without attaching and another answer that allowed me to run a script as another user. I want to SSH from Server 1 -> Server 2 and run a ...
0
votes
0answers
19 views

DEB postinst script that edits $PATH globally for all users including root? [duplicate]

I am building a deb package and I need to edit globally the $PATH in order to run a command everywhere and it runs the binary. So far I have no success. Trying this on Ubuntu 16.04/18.04. Right now my ...
0
votes
0answers
56 views

How to get git bash to accept SSH keys from Ubuntu install

I have a previous Ubuntu install that I need to get the SSH key to work now with git bash. I have followed a few guides and none have worked. Currently I have /c/Users/josh/.ssh set when I go to my ....
0
votes
1answer
12 views

Difference in Array Notation in Bash

What's the difference between these two array notations? "${aws_user_roles[@]}" "${aws_user_roles[*]}"
0
votes
0answers
36 views

iptables block all traffic from a IP after TCP handshake completed

Other than writing a script that monitors the log file to see if a full TCP connection has been created to a certain port is it possible to create a rule using the recent table that will block all ...
0
votes
2answers
31 views

Adding a new line from file using sed

i'm trying to add a new line with data from a file to another file. The problem is, the data in the source file is with whitespaces so i do not get everything included. Here's my code: Source File: ...
1
vote
3answers
125 views

Parsing Command Output in Bash Script

I need a bash script that takes the output of a shell command and parses that output to pull out the id, and website url for each line in the table that can then be used to execute additional bash ...
0
votes
1answer
36 views

Passing a Bash array as arguments

I have this script: #!/bin/bash -x NEW_ARGS=() for (( i=1; i <= "$#"; i++ )) do if [ -f "${!i}" ]; then NEW_ARGS+=" $(basename ${!i})" else ...
0
votes
2answers
66 views

AWK, cut or ced…double parsing mail log to get authentication failures

I would like to parse mail log files, which originally look like this: 2018-10-23 23:27:51,026 INFO [ImapServer-4] [ip=10.10.11.50;oip=168.232.24.2;via=10.10.11.50(nginx/1.7.1);ua=Zimbra/8.8....
0
votes
0answers
37 views

How to query custom installed rpm package

Generally, if I need to query an rpm based package I use following commands: rpm -qi package rpm -ql package # to get installed binaries of package rpm -qf path to binary # to get related package ...
-1
votes
1answer
27 views

Can't login after installing with, playing with, and uninstalling zsh

The really bad news here (I think) is that I use the root account to log in to my Centos 7 box. The other day I saw an article about zsh, and installed it out of curiosity. Today I decided it's ...
0
votes
0answers
25 views

How can you add bash script in custom iso & after iso installation with pxe boot that script can used as start-up script?

I have created a automated VM with virt-install & install automated centos 7 on it with pxe network boot.. I want to run a bash script on this VM after reboot of centos 7 installation. How can ...
0
votes
1answer
38 views

~/.bashrc is NOT sourced on ssh 'command'

At the end of .bashrc I added: touch /tmp/bash_noninteractive_test Run: /usr/bin/ssh -v -C root@example.com 'ls' On the host (logged in interactively before): % ls -l /tmp/...
0
votes
1answer
37 views

.bash_profile not read over parallel ssh connection (hss)

I'm using hss (https://github.com/six-ddc/hss) to connect to 3 Ubuntu servers (the same edition). The problem is on 2 of them ~/.bash_profile is not read over hss, even though it is being read when I ...
1
vote
1answer
38 views

write/wall message to users with color

Is it possible to send messages to other users (i.e. via the wall and/or write commands), with colors in the message? I have a shutdown script that kicks other users off of a shared file server, and I ...
0
votes
2answers
50 views

how to filter with grep for hours?

I have the following log file, I want to cut the file with a grep but I only list the content that occurs from hours 7 to 19. Oct 11 05:26:56 cuervo sshd[983]: Server listening on :: port 22. Oct ...
1
vote
3answers
75 views

How to compress spaces in bash command output?

I work on a small screen and I'm trying to make the output of this command shorter, but I cannot get it to work. Command: docker container ls --all Output (too wide!): CONTAINER ID IMAGE ...
0
votes
1answer
30 views

Is it possible to whitelist a domain and all subdomains in IPTABLES?

#!/bin/bash IPT="/sbin/iptables" Using a drop all policy for IPTABLES echo "Set default policy to 'DROP'" $IPT -P INPUT DROP $IPT -P FORWARD DROP $IPT -P OUTPUT DROP Trying to define specific ...
2
votes
2answers
110 views

SSH from A through B to C, using private key on A

These is my scenario: Host C is not accessible from A. Host B is accessible from A. Host C is accessible from B. Both B and C have ~/.ssh/id_rsa.pub (from A) in authorized_keys B does not have the ...
0
votes
0answers
27 views

Find and cp whilst preserving modified date on files and folders

Morning all, I have this script that will find all files from the last 7 days and transfer them to a different location. I need it to maintain the modified date for the files and folder, currently ...
0
votes
1answer
47 views

Grepping 'nginx -t' for a result

Strangely enough this wont work for me. nginx -t | grep -c 'successful' | awk '{if ($0==0) print "not found"; else if ($0>0) print "found"}' It returns a not found even though the result is as ...
0
votes
2answers
59 views

Bash function doesn't work for remote ssh command execution although interactive shell function fine

I define a function in .bash_aliases file and include it in my .bashrc file. My .bash_aliases file: function dmidecode() { if [[ $1 == -t && $2 == 1 ]]; then cat ~/...
0
votes
1answer
39 views

SSH tunneling and running commands inside Docker image

I'm pretty new to Docker and have a docker image, I need to do following: perform SSH tunneling to three different addresses from inside the docker image that to the outside. Then, I need to run a ...
0
votes
1answer
65 views

How to execute 2 scripts on a server via ssh by chaining them and within only a single connection? [closed]

I have these 2 commands that I send to my server: - cat ./script1.sh var1 var2 | ssh my_user@my_server.com - cat ./script2.sh var3 var4 | ssh my_user@my_server.com This is a part of Gitlab CI, but ...
0
votes
1answer
45 views

How to simulate pressing Enter? [closed]

I have this in my bash script: ENV_VAR1=123 nohup my_app & When I run, it prints this $ nohup: appending output to 'nohup.out' # <here is a new line> and expects me to press Enter so ...