Questions tagged [shell-scripting]
Programming in an Interpreted language executed by a running Shell
622
questions
0
votes
1
answer
1k
views
whats the diffrence between "command.sh > /dev/null 2>&1" vs "command.sh 2>&1 >/dev/null"
I have many shell and python scripts on my crontab that ending either with:
command.sh > /dev/null 2>&1
or
command.sh 2>&1 >/dev/null
I know that:
> is for redirect
/dev/...
0
votes
1
answer
372
views
finding docker images with tag and name
when I do docker images I have below docker images as list where there are images with multiple tag and also image with latest tag value.
REPOSITORY TAG ...
0
votes
1
answer
2k
views
how to programatically set nginx configuration directives to nginx.conf?
I am trying to make a shell script to auto install a web app and the script needs to set client_max_body_size to a bigger size, at some point.
Of course, it's possible to set this directive using nano ...
1
vote
2
answers
2k
views
Why does `ps -x | grep foo` include the grep command?
I know that it does (often) include the grep process and I know adding | grep -v grep or grepping on [f]oo instead will prevent it, but my question is more about order of operations I guess.
For ...
0
votes
2
answers
6k
views
cURL POST bash script adds single quotes to variables with spaces
The first 3 variables will always have no spaces. The fourth "slacksitename" has spaces
ip=“x.x.x.x"
record_name=“demo.xyz"
slackuri:”WEBHOOK"
slacksitename:”123 Main St"
...
-2
votes
2
answers
198
views
How to create a script to check logfile
I want to create a script where i check the logfile every 5 or 10 minutes to know if the service is up and running, and also, to know if the logfile is receiving and sending these files that are being ...
0
votes
0
answers
954
views
Shell Scripting - Multiple Process ID's instead of one
I'm writing a simple bash script to shutdown tomcat, and if it doesn't stop gracefully then check if the tomcat's PID still exists and kill it.
I pass the tomcat name as a variable to the script as ...
1
vote
1
answer
214
views
How to delete the grepped iptables
I have iptables starting from cali-
root@Ubuntu-18-VM:~# iptables -S | grep -oP '(?<!^:)cali-[^ ]+'
cali-FORWARD
cali-INPUT
cali-OUTPUT
cali-cidr-block
cali-from-hep-forward
...
0
votes
1
answer
341
views
Bash: improper function/usage of command basename
What I want in the following command is to find particular files and move them to the other directories while appending ".log" to the destination filename.
find /src/dir/ -type f -mtime +3 -...
0
votes
1
answer
1k
views
Kubernetes limit number of simultaneous pod restarts over whole cluster
We have a 6 node Kubernetes cluster running around 20 large replica set workloads (Java services). Each workload pod (1 pod per workload) takes about 30 seconds on average to start and use a lot of ...
0
votes
1
answer
215
views
Expecting a password in the middle of script in RHEL [closed]
I want to copy files from another server it's expecting a password to copy... Where as sshpass is working in Ubuntu, but in RHEL is there a way to pass the password in the script.
0
votes
2
answers
584
views
Howto start and detach screen with user environment on startup?
I want to start screen and put a couple of programs running inside on startup. I've seen many similar posts but none answered my question.
so I put in rc.local following 2 lines:
screen -dmS scr ...
0
votes
0
answers
220
views
strings are over-writing variables when using echo
I've currently got an IP address in a variable and I'm trying to echo that variable with some string at the end:
echo $INTERFACE_IP
echo ":0.0"
echo "${INTERFACE_IP}:0.0"
And what ...
1
vote
1
answer
414
views
Command works from bash prompt; does not work from within shell script
I'm trying to use IPMITOOL to query a bunch of OOB NICs to get their MAC addresses.
When I run:
ipmitool -I lanplus -H 1.2.3.4 -U USER -P PASS lan print
I get:
MAC Address : aa:bb:cc:dd:...
0
votes
2
answers
1k
views
Download with Wget only if new version
Good morning,
I have a custom software that updates with a custom script.sh.
Part of the file goes something like this:
if [[ $software == A ]]
then
echo "downloading package..."
...
0
votes
1
answer
322
views
Taking input on remote vm
below is my use case , I have to take a input from a user for a specific command which need to run on a remote machine.But my problem is I am not able to access that machine directly so what I am ...
0
votes
1
answer
691
views
How return to prompt after execution of script that spawns a daemon?
$ cat appleclue.sh
#!/usr/local/bin/bash
source ~/.venv/appleclue/bin/activate
cd ~/applications/appleclue/appleclue-web/
git pull
pip install -r requirements.txt
python3.9 manage.py migrate --...
0
votes
1
answer
725
views
FreeBSD: Cant stop program started by rc.d ("is not running")
I've created a rc script to start gunicorn as a daemon on boot.
#!/bin/sh
# PROVIDE: gunicorn_appleclue
# REQUIRE: DAEMON
. /etc/rc.subr
name=gunicorn_appleclue
rcvar=gunicorn_appleclue_enable
...
1
vote
1
answer
6k
views
How to automate ssh password Windows / Git bash - already with the installed software without needing to install
I have a VM that has the fixed snapshot, and I have not the right to install anything
How I can achieve the goal?
Passing password to ssh connection Windows 10, using git bash without needing to ...
0
votes
1
answer
397
views
On CentOS 8 in profile.d do I need to add my script related to environment variables to both an .sh and .csh file?
I need to add environmental variables related to proxy servers to allow my node.js app to communicate with reCAPTCHA Enterprise on Google Cloud.
When I run the scripts from Accessing Google Cloud APIs ...
0
votes
0
answers
143
views
Issues with Bash Script to SSH and Copy String Variables from a CSV to a remote file
Here is my script
#!/bin/bash
clear
PSQLSTART="INSERT INTO TABLE (Name, Description, Field3, Field4, Field5, Field6, Field7, Field8, Field9, Field10, Field11, Field12, Field13, Field14, Field15,...
0
votes
0
answers
280
views
Using setuid in a Shell Script on Ubuntu 20.04
So I have a Laravel PHP app on Nginx on Ubuntu 20.04. I have a simple deploy.sh script that will:
Put Laravel into maintenance mode, so it returns a 503 error if anyone visits the site
Pulls down the ...
0
votes
1
answer
2k
views
Jenkins vs shell scripts
why would Jenkins get a different result from shell scripts(redhat 7) alone? I have shell scripts that run fine if I execute them from a terminal, however when I run the scripts from Jenkins they get ...
0
votes
2
answers
239
views
Best and simple way to prevent automatic backups filling all disk space in Linux, before it actually happens
Which do you think is the best and most simple way to prevent automatic backups filling all disk space in Linux, before it actually happens?
I would like to automatically recycle the oldest ones when ...
1
vote
2
answers
798
views
Bash script - check if a variable is located between 2 others variables?
In a Bash script I want to check if var1 is located between var2 and var3.
But I can't find how to do it.
Something like this.
var1=15
var2=10
var3=20
if [ "$var1" is located beetween "...
0
votes
1
answer
229
views
Monitor Docker Container for No Output
I have a long running process in a docker container that is setup like this:
Dockerfile
...
ENTRYPOINT ["./invoke.sh"]
invoke.sh
#!/bin/bash
./long-running-command
If long-running-command ...
0
votes
1
answer
636
views
Diff says file does not exists – why?
I transfer a file from a remote server to my local server. If this is done I do a diff to check if both files are identical to check if the transfer was successful. So I do this:
ssh -o ...
2
votes
2
answers
557
views
Can't access instance after setting up iptables rules
I'm trying to setup some rules to block all ports except 21 and 22 on TCP (SSH and FTP). But when I try to run this script I get locked out of my instance and can't access it. This is the script:
# ...
0
votes
1
answer
279
views
Run xterm script from /etc/profile leads to "cannot load font"
I want to auto-start a shell script and therefore I added this line to my /etc/profile:
/bin/su -c "/path/to/my/script" user -
the script itself starts a xterm shell command and output ...
0
votes
1
answer
174
views
COMMAND TO DISPLAY SPECIFIC LINES IN A SCRIPT [closed]
I have a script containing 5 lines in it. what is the command to view only 1st and last line in the script in one single expression.
0
votes
0
answers
1k
views
How do I get the Current time in milliSeconds in a Shell script in buildroot environment?
MYENV=$(date +"%s%N")
printf "Time:: %s\n" "$MYENV"
or
MYENV1=$(date +"%T%N")
printf "Time:: %s\n" "$MYENV1"
I tried above methods, they ...
0
votes
2
answers
327
views
Bash script to create variables from and run commands on each item in an external list
On my local machine I have a text file containing a list of IP addresses and directory names.
list.txt
# Comment for Server 1
XXX.XX.XXX.X
DIRECTORY-NAME
# Comment for Server 2
XXX.XX.XXX.X
DIRECTORY-...
3
votes
3
answers
10k
views
Using if else statement inside shell module in ansible playbook
I am trying to run if else statement inside shell module in ansible playbook but looks like my else statement is not executing in any case.
- name: verify application/database processes are not ...
0
votes
2
answers
505
views
Update crontab of my web user using "sudo"
I need to update the crontab of my web user (the user that is executing all websites). In my crontab I'm using shell script with commands that needs to use "sudo".
The script is well ...
-1
votes
1
answer
271
views
Can somebody help me on how to zip these individual log files within while loop
I am able to break o/p of a big logfile (filename.log) into individual log files of 1 min each (filename.log.140108) using while loop, but I want these files to be saved as zip files due to capacity ...
1
vote
1
answer
2k
views
How to calculate CPU and memory utilization on solaris box
I am trying to write shell script to calculate memory and cpu utilization on solaris box.
For CPU utilization, I tried below command but I want to append date, time and host name in same command but ...
0
votes
1
answer
708
views
Copying Content from a file to another when a new line is added using poweshell script
I have a file named server1.txt and one more file named server1_copy.txt. In server1.txt, all logs will be added from the application. So whenever a new line is added in the server1.txt, we need to ...
0
votes
1
answer
507
views
how to run a bash backup script with simultaneous processes without getting stuck with infinite looping?
I wrote this script for run postgresql pg_dump of multiples schemas. Since it takes much time to finishes all i'd improved it by running simultaneous dumps with this:
for SCHEMA in $SCH
do
while [ $(...
0
votes
2
answers
804
views
A shell script to ssh, watch log file, and run command
I want a shell script that connects to a server via ssh, starts watching a log, and then touches a file. It's important that I do them in that order, because I want to see in the log the effects of ...
0
votes
0
answers
669
views
Powershell script to delete oldest files
I DO NOT want to "delete files older than X days." If I wanted to do this, I'd just pick one of the thousands of scripts out there that have already been written for that purpose, and I ...
0
votes
1
answer
711
views
su - with automatic change directory once su command is done in shell scripting
im not familiar in shell scripting but im trying to achieve at least this script but my problem is once superuser rt is done logging in it brings me to this
[rt@superuser root]$
instead of reading ...
0
votes
1
answer
167
views
Trim and allign an output of command in expect script
{ echo ' ' ;echo ' IP : ' ;ip route get 8.8.8.8 | cut -d' ' -f7,8 | tr -d 'src' ;echo ' ' ;dmidecode -t bios | grep -iw 'Version' ;echo ' ' ;}
the output of above command mentioned is:
IP :
10.0.0.1
...
0
votes
2
answers
661
views
saving sql dump error in a file
I want to save error if error comes, into a file. But error not redirecting into file.
I get below error and its not redirecting into file.
mysqldump: Couldn't execute 'SHOW FIELDS FROM `v_comloc`': ...
1
vote
1
answer
2k
views
I'm not good at scripting...How best can I update the IP address on a debian server running live from PXE (DHCP reservations are not an option) [closed]
This is more a brain dump than anything at this point, but I'm stuck and help would be appreciated!
I have a really complicated set of limitations on 3 of my servers that necessitated running the OS ...
0
votes
1
answer
1k
views
Case statement not working properly in shell script [closed]
The case statement in the bash script does not work. Below is the snippet of my shell script.
usage="Usage: \n servicer [ service argument ] {-h}\n"
invalid="\n not a valid option\n&...
0
votes
1
answer
407
views
Parsing Command Response in Bash Script
I need a bash script that takes the output of a shell command and parses that output to pull out the state. If the State is: Bad, an email should be sent.
~$ bucardo status
PID of Bucardo MCP: 2074
...
0
votes
1
answer
5k
views
Systemd: Unit-file timeout after start
I have written a bashscript with the following content:
#!/bin/bash
cd /opt/ut_server/System
./ucc-bin-linux-amd64 server DM-Rankin?game=XGame.xDeathMatch?mutator=AntiTCC2009r6.MutAntiTCCFinal,...
8
votes
3
answers
5k
views
How to delete docker images older than x days from docker hub using a shell script
How to delete docker images from docker hub using a shell script.
I want to delete all images from docker hub older than past 50 days of a private docker hub account.
Any ideas? Which tools to use ...
2
votes
4
answers
5k
views
How to post logs to Cloudwatch with CLI?
Im tring to create a bash script that checks the status of the website, Im using this command:
This one to create the logstream
aws logs create-log-stream --log-group-name "WebsiteStatusMessage" --...
0
votes
2
answers
1k
views
Can't get cron to output a GUI message / how to make user aware cron is being executed
I need to run, on Ubuntu 18.04, via cron a script, myscript.sh that I want, among other things, to display to the user a message when it is being run so that he is aware that cron is being run (...