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/...
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
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 ...
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 ...
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 ...
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
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/*...
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 "...
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 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 ...
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
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 ...
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 ...
-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
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 "...
0 votes
1 answer
81 views
Change Ubuntu server password every 7 days and do autologin
am working on a scenario where i need to Change Ubuntu server password every 7 days and do autologin. i tried with breaking the problem: command to create user with password: useradd -p $(openssl ...
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 ...
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 ...
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 ...
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
0 answers
90 views
GAWK not running in crontab
I have the below script running successfully manually. But when it is executed in crontab (below), I dont see anything happening. Script #!/usr/bin/gawk -f #!/bin/bash PATH=/usr/local/bin:/usr/bin #...
0 votes
1 answer
208 views
Variable in AWK
How can I add a variable within awk command? below is my command: cat /home/ubuntu/test/copy.txt | awk 'NR==21{print ".host = "$line";"}1' $line is basically an IP address which ...
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 ...
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 ...
1 vote
1 answer
57 views
Scripted Password Change Does Not Survive Reboot Unless One Login Occurs - Debian 11
I am trying to automatically set the root password to random characters via bash script. The script is part of a Vagrant shell provisioner. If the script runs the password change only, I am able to ...
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 ...
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 /...
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. ...
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 ...
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
68 views
Remove bunch of disconnected LUNs by shell script (regex issue)
Have a problem with my script, don't want to run same procedure 200 times with changing LUN number. Remove the multipath device from ALL paths to the LUN, run echo 1 > /sys/bus/scsi/devices/${H:B:T:...
0 votes
0 answers
476 views
Can a bash script detect if it's **not** being run inside a `systemd` service?
I have a bash script. This script can be started as part of a systemd service (or transient systemd task with systemd-run). One can also run it stand alone. How can I see if “the current script” is ...
1 vote
1 answer
337 views
Powershell script credentials prompt appears before read-host executes
I'm calling a script inside another script: ... ... powershell C:/temp/script2.ps1" ... ... That joins a VM to a domain after downloading some things. However, when the script runs, the prompt ...
-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 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 ...
0 votes
0 answers
121 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 ...
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 ...
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
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 ...
0 votes
1 answer
154 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 $...
0 votes
1 answer
596 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 && ...
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
1 answer
212 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 ...
0 votes
1 answer
548 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/...
0 votes
1 answer
257 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 ...
-3 votes
1 answer
79 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 ...
0 votes
1 answer
511 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) ...
0 votes
0 answers
330 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 ...
1 vote
0 answers
934 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 ...
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 ...