Stack Exchange Network

Stack Exchange network consists of 175 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
3answers
33 views

What is the difference between running a command in ssh shell manually vs running 'ssh user@host <command>?

I was assuming it's the same, but it's not. In my particular case a build script is working fine when executed as ./build.sh from ssh session on the build server like this $ssh user@host $./build....
0
votes
2answers
35 views

Connect to remote server through another server buy one line command

I have two servers: server1 and server2 I can connect to server2 only from server1 by a specific user. Currently, I connect like this: My computer ssh user@server1 On server1: su - user2 After this ...
0
votes
0answers
7 views

Wrap bash script call with connect / disconnect from VPN

Once or twice a day, when the service I'm building is in production I'll have to read a database that sits behind a VPN. Now, in the development phase I've been doing as follows. As root user I run: ...
-1
votes
1answer
28 views

How can I provide software for userdata?

I've got a userdata file that uses the aws and jq commands, but since these aren't ubuntu 18.04 AMI. How can I make software available for userdata? I tried making a new AMI with those installed. It ...
0
votes
1answer
62 views

Error running a startup-script: home environment variable not set in redhat instance running on GCP

I'm having trouble to understand the shell environement that is used to run startup scripts. What difference with a login session? If I set a simple starup script to print the env variables: ...
2
votes
1answer
30 views

How to prevent Git client hanging during post-receive hook

I have a Git repository that contains a collection of config files and python scripts. On the server repository, I have a post-receive hook that will: checkout the master branch, setup a python ...
-1
votes
0answers
8 views

How to run sh file in Asterisk dial plan

How do i run sh file from Asterisk dial? tar -zcvf /backup/"backup_chan_folder_-$(date +"%Y-%m-%d").zip" `/root/chan/*.*` extention conf file exten => 2004,1,Playback(restarting) exten => ...
0
votes
1answer
32 views

script to grep a pattern in a file and perform an arithmetic operation from the extracted string

I am a novice at scripting so looking for some pointers as to how to solve my problem. There is a log file (server.log) which keeps track of the number of connections being made to a database . ...
0
votes
2answers
31 views

Escape all characters that shell or sqlplus need escaped in any password given

You may try for yourself by creating this user: CREATE USER "karl" IDENTIFIED BY "/?'!@#$%^&*()_+=-~`" (Maybe there are other symbols I should have included for my testing, but that seemed ...
1
vote
1answer
19 views

How to detect NVIDIA GPU with Puppet

I have some tasks I only want to run on machines that have NVIDIA GPUs. Is there a good way with Puppet to be able to determine if a specific agent has an NVIDIA GPU or not? I'm able to do it in bash ...
-1
votes
1answer
42 views

Run iptables-save before shutdown/reboot

I have installed iptables-persistent on my Ubuntu 18.04 server and search for a solution that I don't need to save the iptables configuration (iptables-save > /etc/iptables/rules.v4) every time before ...
0
votes
0answers
10 views

nginx - subs_filter drops domain for some substitutions in html response

I'm experiencing a very particular issue with nginx and it's subs_filter module. Nginx version being used is 1.13.5. The below is my location block: location ~ ^\/([a-z][a-z])\/blog\/.*$ { ...
0
votes
0answers
23 views

Add rule in .htacces only if domain name begins with <regular-expression>

I have to add a rule in a server that host many sites. This rule must be added only in those .htaccess files that belongs to a site with domain beggining with "dev-" or "review-". I have this: #!/...
0
votes
2answers
56 views

How to rename system commands e.g., shutdown in Ubuntu Linux

While working on redis server, I come to know there is an option to rename you scracy command to avoid accidental update. Is there any option for bash i.e., Ubuntu Linux especially shutdown, rm and ...
0
votes
1answer
36 views

bash does not show prompt (prompt missing)

I have a server that does not show standard bash prompt, after I log out from the machine. If I ssh to this server, I can do all operation there (e.g. ls, cwd, etc) Tried to reinstall bash (sudo apt-...
1
vote
1answer
31 views

Sendmail bash script invoked by cron can't read from stdin

I try to write a little script that overwrites from adress of nullmailer. Nullmailer has an option "allmailfrom" you can put a mail adress into /etc/nullmailer/allmailfrom and all mails sent have this ...
0
votes
2answers
48 views

How to run in background a Linux command in Windows WSL (Ubuntu1804)

In the effort to bring some of the Linux advantages to my customers running Windows 10, I've developed a few bash scripts in order to automate some of their everyday tasks. I use to let them run the ...
3
votes
3answers
501 views

Division does not work in bash

I'd like to calculate some information from a file but division does not work. If I change the / to a + or -, this calculation it doing right. Any ideas? #!/bin/sh FILE=/tmp/stats for EMPTY ...
1
vote
0answers
24 views

How to prompt user for password and get result without gksudo?

There is no more gksudo command as well as gksu package in some linux distros. How do I achieve the same using previous command like DISPLAY=:0 gksudo -p -m "Enter your password to apply changes." ...
-1
votes
1answer
37 views

how to make aws prompt colored

I'm using ssh for ec2 instance but the colour for prompt is plain ubuntu@ip-11-2-2-44: I can't seem to understand this. Can anyone tell me how do I fix this? Make it coloured or something. It's ...
0
votes
2answers
21 views

Extract text between 2 strings only if another string is present

I have a quit large XML file that I am trying to modify only certain lines of the file. The lines I want to modify will all contain in them. On those lines, I want to have only the text between 2 ...
1
vote
1answer
42 views

Enter at the end of a specific line

I have the following file.txt that follows the same pattern and I want to modify it where this file is by adding an ip: # gfhfhgfh gfhfghgfhgfhgfh MACs # access USER CONSOLA *,!10.249.247.3,!10.249....
0
votes
0answers
24 views

removing masquerade with a bash script

I have currently setup a VPN on a RPi using Strongswan where everything is working semi well between site and server. However, I do not want the device to have internet connection. (I installed ...
-1
votes
1answer
41 views

kpcli bash script to automate entries

I am trying to create a bash script which uses kpcli in order to automate entries into a kdbx file. While searching over here I found out that you could use expect and send, however this does not ...
0
votes
1answer
17 views

detect network status even if it is disconnected for a millisecond shell script

I have this shell script which keeps running continously. #!/bin/sh while true; do ping -c1 www.google.com > /dev/null; done When I disconnect my lan cable this script throws error in the ...
0
votes
0answers
31 views

Get ESSID & BSSID of open networks in Terminal

I'm looking for a way to get BSSID and ESSID of all open (not encrypted) wireless networks in my surroundings with a bash command. It would be even better, if could filter out networks with a too low ...
1
vote
0answers
46 views

Banning IP addresses after repeated login attempts to specific URL

I have a few questions regarding banning IP addresses after x many login attempts to a certain url on my website. Mostly, what would be the recommended or most efficient way? Example URL: https://...
0
votes
1answer
76 views

Record ssh REMOTE_USER in audit or history logs

In our company we usually have a single production user user and we ssh to our servers via pasword-less login with ssh keys. Now, quite a few people work on those servers and sometimes we need to ...
0
votes
0answers
25 views

Disabling systemd messages that interfere with running BASH script

How can I disable systemd messages that pop up in my BASH script once in a while (for example, after I login to the machine via SSH from somewhere), like in the screenshot below ? The BASH script uses ...
-1
votes
1answer
55 views

Script on Linux only gives me “no such file or directory” [closed]

I've come across a problem, I am writing a script that would find the biggest file in directory and sub-directories, then show full path on screen. Can't seem to get it working. The error I'm getting ...
2
votes
1answer
112 views

Totally automating Apache on whatever distro

The problem I'm having seems to be true to all distors but let's assume I use an all-default debian-stable (server), and ran apt update -y. Installing, upgrading, restarting as well as enabling or ...
1
vote
2answers
69 views

Send email if script outputs string

I found this line: sh script.sh | grep 'NO' 2>&1 > grep.log && /usr/bin/mail -s "grep found something" m@mail.com < grep.log which will write the output of script.sh to grep.log ...
0
votes
1answer
21 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
1answer
64 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
81 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
48 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
57 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 ...
1
vote
1answer
51 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
13 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
32 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
47 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
16 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
63 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
57 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
134 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
43 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
48 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
2answers
274 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
30 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
79 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 ...