2022 Developer Survey is open! Take survey.

Questions tagged [shell-scripting]

Programming in an Interpreted language executed by a running Shell

Filter by
Sorted by
Tagged with
1 vote
1 answer
22 views

bash script – MySQL commands and variables

I have a bash script who automate a Nextcloud server installation. To run MySQL commands I use the mysql -e command user@hostname:~$ mysql -e "CREATE DATABASE ‘NextcloudDataBaseName’" I ...
user avatar
  • 67
0 votes
0 answers
15 views

Script to reassign floating IP address to my other machine running Ubuntu

I have a floating IP(X.X.X.191) assigned to the machine (Y.Y.Y.106) currently running ubuntu. Now I want the same floating IP to be assigned to my other droplet(Z.Z.Z.252). On digital ocean I can do ...
user avatar
0 votes
0 answers
23 views

How to pass multiple arguments through ssh and use those arguments in the ssh script?

I have written one script on lets say server1 and from that script I want to execute script Start_UI_AdminApp.sh on server2 through ssh. I also need to pass the arguments while executing this ssh ...
user avatar
0 votes
1 answer
38 views

Shell script to check resolv.conf [closed]

I need to write a shell script which checks the contents of resolv.conf Eg domain example.com search abc.com abc.org abc.net nameserver 1.1.2.2 nameserver 3.3.4.4 abc.com/abc.org/abc.net can appear ...
user avatar
0 votes
0 answers
28 views

When calling script from jenkins it is not working as expected

we have one react application and start it using pm2 with pm2 start manually. We have written one script to run it, it is working as expected when we run script manually on server. But when calling ...
user avatar
0 votes
1 answer
13 views

Shell script not reading the file as expected

Below is the script trying to be executed: read n for ((i=1;i<=$n;i++)) do file=createserver"$i".json echo $file instanceid[$i-1]=$(jq -r '.instance.id' ./$file) echo $instanceid done $...
user avatar
0 votes
1 answer
32 views

Variables on set-hostname and mv command in shell script

I have the below script in Shell: read n for ((i=1;i<=$n;i++)) do echo "Connecting to $publicip" ssh -i ./key.txt root@$publicip 'hostnamectl set-hostname autotest$i.domain.com && ...
user avatar
0 votes
1 answer
70 views

Run commands that run in a shell as a script

Running the following commands in a shell runs without issues: ssh user@machine systemctl status my-service.service ssh user@machine sudo systemctl stop my-service.service scp -r ./my-service/* user@...
user avatar
0 votes
1 answer
20 views

Shell Script to Move a File Into Another User's Directory?

I'm running a Ubuntu 16.04 server. On my server, I have a file in directory /home/userA/dirA: userA@myUbuntu:~$ userA@myUbuntu:~$ pwd /home/userA userA@myUbuntu:~$ userA@myUbuntu:~$ ls -l total 8 ...
user avatar
  • 111
0 votes
1 answer
66 views

Using awk with column number in a bash script

I'm using a command like this to get some connections from nf_conntrack: awk '($3 == "tcp") && ($6 != "TIME_WAIT") && ($10 == "dport=1234")' /proc/net/...
user avatar
  • 33
0 votes
1 answer
24 views

How monitor open files and kill its PID by shell script?

My system gets me an error that saying 'Too many open files'. I investigated this error and turned out that /usr/bin/uwsgi created sockets(?) more than 1020. If it creates more than 1020, I guess, the ...
user avatar
-3 votes
1 answer
35 views

Nested directories file restore

I recently took backup of one of my server's drive on AWS using one of the software and now at the time of restoring it i found out it took too long to restore as its having billions of files to ...
user avatar
  • 39
0 votes
1 answer
45 views

Automating GDB memory dumps [closed]

I'm trying to dump memory from a process on my Linux machine using GDB, but I'm trying to automate this using a script. So far I've been using the following commands (example): $ gdb --pid [pid] (gdb) ...
user avatar
0 votes
0 answers
55 views

Running ps command with 'Irix mode' off

I know that within the interactive 'top' screen, I can press 'Shift + i' to turn off 'Irix mode' Is there a way to do the same thing with 'ps' command? I am trying the below mini script to print out ...
user avatar
1 vote
0 answers
114 views

How to export the details of a digital certificate (.cer file) to a csv file using powershell?

I have a digital certificate that I'm using for a specific task. I need to export the details of the certificate such as the serial number and issuer to a csv file that is already on my computer using ...
user avatar
  • 11
0 votes
1 answer
288 views

Handle exception with long paths in Powershell

I am new here and I facing issues with my powershell script whith long paths. This script aims to get relative path and hash from files/folders and its subfolders. It works with some with others I get ...
user avatar
  • 1
0 votes
1 answer
142 views

Ansible blockinfile module - insert insert lines of code

I try to insert lines of code (shell script) with Ansible blockinfile module. name: Customized prompt blockinfile: path: /etc/profile.d/customized_prompt.sh create: yes block: | #!/bin/bash # ...
user avatar
  • 67
0 votes
1 answer
294 views

Ansible playbook rebooting the server , wait till reboot complete

I'm facing a issue while executing shell script with ansible playbook. Issue: I'm losing a connection with remote server because shell script is rebooting the server. My Ansible playbook - name: ...
user avatar
0 votes
1 answer
64 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/...
user avatar
0 votes
1 answer
40 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 ...
user avatar
  • 172
0 votes
1 answer
290 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 ...
user avatar
1 vote
2 answers
1k 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 ...
user avatar
  • 113
0 votes
2 answers
3k 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" ...
user avatar
-2 votes
2 answers
83 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 ...
user avatar
  • 1
0 votes
0 answers
139 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 ...
user avatar
  • 1
1 vote
1 answer
89 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 ...
user avatar
  • 255
0 votes
1 answer
95 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 -...
user avatar
0 votes
1 answer
214 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 ...
user avatar
  • 101
0 votes
1 answer
95 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.
user avatar
0 votes
2 answers
63 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 ...
user avatar
  • 23
0 votes
0 answers
25 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 ...
user avatar
0 votes
1 answer
188 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:...
user avatar
  • 3,207
0 votes
1 answer
159 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..." ...
user avatar
0 votes
1 answer
105 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 ...
user avatar
  • 1
0 votes
1 answer
111 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 --...
user avatar
0 votes
1 answer
261 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 ...
user avatar
0 votes
1 answer
93 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 ...
user avatar
0 votes
0 answers
59 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,...
user avatar
  • 1
0 votes
0 answers
130 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 ...
user avatar
0 votes
1 answer
568 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 ...
user avatar
0 votes
2 answers
122 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 ...
user avatar
  • 11
1 vote
2 answers
168 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 "...
user avatar
  • 67
0 votes
1 answer
133 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 ...
user avatar
  • 13
0 votes
1 answer
254 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 ...
user avatar
2 votes
2 answers
217 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: # ...
user avatar
0 votes
1 answer
128 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 ...
user avatar
  • 101
0 votes
1 answer
61 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.
user avatar
0 votes
0 answers
104 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 ...
user avatar
0 votes
2 answers
136 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-...
user avatar
  • 149
2 votes
3 answers
4k 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 ...
user avatar

1
2 3 4 5
12