Questions tagged [shell-scripting]
Programming in an Interpreted language executed by a running Shell
624 questions
0 votes
0 answers
25 views
crontab script is not running in other server. In the server we copied, it's running fine [duplicate]
see below details eccdbpvm02:/mnt/HANA/E1P/backup/data/DB_F1P # crontab -l 05 00 * * * /usr/sys_scripts/clear_log >> /usr/sys_scripts/log.txt 2>&1 eccdbpvm02:/mnt/HANA/E1P/backup/data/...
192 votes
8 answers
440k views
How do I sleep for a millisecond in bash or ksh
sleep is a very popular command and we can start sleep from 1 second: # wait one second please sleep 1 but what the alternative if I need to wait only 0.1 second or between 0.1 to 1 second ? remark: ...
1 vote
2 answers
825 views
How to get global IPv6 address of the current machine?
I a bash script, I want to obtain the global IPv6 address of my machine for a given network adapter (on my case 'ens18'). To get started, I issued the following command: ip -6 addr This gives me the ...
1 vote
1 answer
122 views
shell script in $PATH does not execute
I have a couple of custom scripts to help me with more or less regular tasks; and recently decided to move them from /usr/bin to ~/bin to have a better overview. I also added home/myusername/bin to $...
0 votes
1 answer
108 views
sh Script Syntax Assistance
I'm trying to write a script that will read search strings from an input file and then execute a command with $string in the middle of the command line. This is an example of the working command line:...
0 votes
0 answers
129 views
Running docker run commands from a shell script without sudo or docker group
I have a containerised command I'd like to run: docker run my_docker_image. Rather than install the command's dependencies into the main computer, I'm packaging them all into an image, that then users ...
0 votes
1 answer
60 views
How to close all files and ports from parent process
I have an HTTP server (source code not accessible and cannot be substituted at this time) running on my Linux machine, which can be configured to execute any commands on requested. However, the HTTP ...
53 votes
7 answers
60k views
How do you set a locale non-interactively on Debian/Ubuntu?
Usually, I run aptitude -y install locales then dpkg-reconfigure locales to set up locale. Now I want to put it into a shell script, how can I reliably do the following, automatically / non-...
7 votes
4 answers
5k views
Robust way to resolve a DNS address in a script (IPv4 (A) and IPv6 (AAAA))?
I have a domain name in a bash variable ($TARGET), and I want to get the IPv4 (A record) address of it in my bash script (I also want to get the IPv6 AAAA record (if exists)), in a robust manner. i.e. ...
0 votes
1 answer
152 views
Why "HISTFILE" variable not read by "readonly" command in shell script?
When I run command bellow in bash shell : if [[ $(readonly | cut -d= -f1 | grep -qo HISTFILE && echo $?) == 0 ]]; then sudo grep -iwo "readonly HISTFILE" /etc/profile /etc/profile.d/*...
2 votes
1 answer
4k views
Running Shell Script without a Password Prompt
I have a shell script that runs on a FreeBSD machine. The script has some commands that needs superuser privileges. I’m executing the script remotely and it’s skipping the sudo’d commands. I tried the ...
28 votes
9 answers
60k views
Running ssh-agent from a shell script
I'm trying to create a shell script that, among other things, starts up ssh-agent and adds a private key to the agent. Example: #!/bin/bash # ... ssh-agent $SHELL ssh-add /path/to/key # ... The ...
0 votes
1 answer
7k 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 ...
1 vote
0 answers
147 views
Split the below HTML text file in two parts using Linux scripting [closed]
I have a html main.txt file, I need help to split it in two parts. headpart.txt and bodypart.txt. Below is my html main.txt text file - Original <p class=\"auto-cursor-target\"><br /...
0 votes
1 answer
1k views
What is the correct way to check monit status/summary success/failure
I have monit utility on production for monitoring several daemons (our micro-services). I'm trying to figure the best way to unmonitor/monitor my daemons while updating them. So, basically I need ...
1 vote
1 answer
301 views
not able to send mails from linux ubuntu : 20.04 by using email mailutils (sendmail or mail keyword)
code : subject="mail subject" body="Hello World" from="[email protected]" to="[email protected]" echo -e "Subject:${subject}\n${body}" | sendmail -f "...
1 vote
2 answers
1k 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
3 answers
7k 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" ...
0 votes
1 answer
4k views
Setup Apache Docker container to keep running after executing php shell CMD
I'm trying to run a Docker container based on: PHP 8.1 Apache 2.4 MariaDB (latest official docker image) Dockerfile: FROM php:8.1-apache WORKDIR /var/www/html/ RUN pecl install xdebug \ &&...
0 votes
1 answer
421 views
Unable to List Contents or Create Files in /var/tmp Folder from PHP Executed Bash Script
Objective: I want to trigger a webhook on a private linux-machine (its a local system not connected to internet), which can delete the spool data generated by CUPS server in /var/tmp folder. To ...
1 vote
1 answer
5k views
How to automate aws cli commands with shell script
I wonder anyone can help me with making a shell script which automate aws cli process for: 1.Creating Security group 2.Set roles to this Security group port 22 and port 80 3.Create a ec2 instance with ...
0 votes
1 answer
891 views
Bash loop through dates
I'm trying to copy data from psql via a bash script now I'm stuck with a loop my bash script is as following: #!/bin/bash DATEBEGIN=2016-03-01 DATEEND=2016-03-31 DATEMONTH=2016-03 echo "Copy ...
20 votes
2 answers
9k views
What does a minus sign inside of dollar brackets of a shell script mean?
In an existing shell script, I'm seeing some variables referenced that either include or end with a minus sign. For example: PID=${PID-/run/unicorn.pid} and: run_by_init() { ([ "${previous-}" ] ...
1 vote
1 answer
10k 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 ...
-1 votes
1 answer
712 views
How to execute remote commands on linux and update return value?
As part of automation in gitlab ci. I am running a terraform template and creating a linux machine. After that, I need to run few commands on the remote machine. I am running those using the ssh ...
-1 votes
1 answer
260 views
Copy/Move Entire Line To End Of The Line Above
I have a file that looks like the following: /path/to/a/very/long/path 0 0 0 0 0 0 I need to move the line starting with a number (this can be any value not necessarily 0) to the end of the ...
1 vote
1 answer
986 views
bash change directory with spaces and backslash
I'm trying to build a script that I need to be quite able to manage directory with spaces or/and backslashes in their name or not. Inside a bash script or directly on bash shell using variables for ...
0 votes
2 answers
407 views
Best Path for nginx Files [closed]
I've always struggled with various paths for nginx files and where they should be positioned. As we know, we can change where we can park both the www directories for our web app, as well as the ...
1 vote
1 answer
273 views
Programmatically (SH Script) check which server is traffic routed/up too by HA Proxy
I have 2 HA Proxy servers with Keepalived configured with them, and have 2 backend servers to which traffic is routed by HA Proxy, am writing a shell script that will sync a directory between backend ...
0 votes
2 answers
2k 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..." ...
1 vote
1 answer
605 views
Powershell Script to check free disk space on servers
I am in need to check free space on servers but I am getting more than enough details. DeviceID : C: DriveType : 3 ProviderName : FreeSpace : 76691152896 Size : 160482455552 ...
20 votes
7 answers
38k views
Get list of transferred files from rsync?
I'm currently using rsync on a script that deploys a PHP application from a staging to a production server. Here is how: rsync -rzai --progress --stats --ignore-times --checksum /tmp/app_export/ root@...
9 votes
3 answers
7k 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
0 answers
327 views
How to enable logging of commands run through shell script in ESXi Hypervisor?
On ESXi Hypervisor, If I run a command on the terminal via SSH, the commands are logged in the shell.log file, i.e if i run this command [root@esxi04:~] ls -la then I can see this command in shell.log ...
1 vote
1 answer
143 views
Hardening the security of a backup shell script of a web-server with mysql database
In the case of a simple web-server with a MySQL database, the script has to dump the database, copy the web-server files and tar everything together. Then a NAS server Rsync the tar file via a "...
-1 votes
1 answer
96 views
Extract Pages from Various PDF Files into New PDF File [closed]
From a.pdf, I would like pages 2 and 5 b.pdf, pages 3 and 4 c.pdf, pages 7, 8, and 9 copied into a new PDF file. All input pdf files are ten pages long. I'm using bash, and plan to make many ...
1 vote
1 answer
3k 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 ...
36 votes
2 answers
49k views
Is it possible to set a timeout on openssl's s_client command?
I've got a script which uses openssl's s_client command to pull certificates for a big set of hosts. Some of these hosts will inevitably be unreachable because of a firewall. Is it possible to set ...
0 votes
1 answer
100 views
time nohup ./script --> the time hasn't been logged [closed]
I need to measure the time that Firefox takes to build itself from the source code. Here's what I do normaly: nohup ./mach build > my_log.log & I then prepended time to it: time nohup ./mach ...
0 votes
0 answers
2k 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 ...
1 vote
2 answers
3k 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 ...
2 votes
4 answers
6k 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
1 answer
659 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 ...
0 votes
1 answer
1k 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@...
0 votes
2 answers
58 views
trying to see if how many times service Accounts was logged in [closed]
Hi I am new to shell scripting ,I am trying to see how many times an accounts were logged in the log file. If an account was logged in more than 20 time I need the name of those accounts to be printed....
0 votes
0 answers
838 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 ...
3 votes
3 answers
13k 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
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 ...
0 votes
1 answer
2k 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: ...
0 votes
2 answers
968 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 ...