Questions tagged [shell-scripting]

Programming in an Interpreted language executed by a running Shell

Filter by
Sorted by
Tagged with
0 votes
0 answers
57 views

Want to use user_data (hardening script) for EKS nodegroups with EKS module (Hashicorp provided)

I am using EKS terraform module (https://github.com/terraform-aws-modules/terraform-aws-eks) to create EKS cluster and it is working fine. I have written shell script to harden EKS worker and I want ...
0 votes
0 answers
28 views

How to establish VPN connection with two factor authentication from CLI

A VPN connection have to be established on demand from a bash script. GUI needed to enter two factor auth code. If you'll try to execute in terminal: VPN_NAME=$(nmcli con|grep "VPN"|awk '{...
30 votes
2 answers
42k 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
4k views

timestamp in shell code script

I'm new in shell coding and hopefully I'm in the right place to ask this question. I'm working with a shell script which collect daily file and send them via ftp. In the filename there are both date ...
0 votes
0 answers
65 views

not able to send mail with attachment from linux ubuntu : 20.04 by using email mailutils (sendmail keyword)

code : subject="Service resilience service status" body="Service is down" from="[email protected]" to="[email protected]" attachment="/home/ubuntu/...
1 vote
1 answer
134 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
1 answer
109 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
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
320 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
531 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
38 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
27 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....
5 votes
2 answers
5k views

Installing and configuring phpmyadmin completely through a shell script

Referencing this tutorial: https://www.liquidweb.com/kb/how-to-install-and-configure-phpmyadmin-on-ubuntu-14-04/ for installing PHP-Admin, after installing the package, on "Step 2: Basic Configuration"...
0 votes
1 answer
184 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
3 answers
82 views

How to output column with special patterns

I have a column, with some words: scatman batman superman scatman scatman batman superman scatman scatman batman superman scatman batman WWWWWWWW superman scatman batman superman scatman I should ...
-1 votes
1 answer
100 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 ...
0 votes
1 answer
60 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 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 ...
1 vote
1 answer
87 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 "...
11 votes
4 answers
32k views

How can I use openssl to get results from HTTP GET requests?

I need to use openssl to perform some HTTP GET requests in a shell script. The line I'm using to do this right now is shown below. This is parsing the content of an XML response of the following ...
0 votes
0 answers
50 views

How to avoid duplicate entries in DNS Bind cache db file?

While running command "rndc dumpdb -cache" it has huge amount of data some duplicate entries like one domain has multiple entries with same target but different TTL, how to reduce like ...
1 vote
2 answers
2k views

Change first character pattern in a file name without changing that same pattern elsewhere in the file name

On a Linux server I have a directory full of files with digits for names. Some of the files start with two zeros such as 00305005. I am writing a bash shell script and one of the steps is to rename ...
0 votes
1 answer
46 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
134 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
177 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 ...
3 votes
5 answers
7k views

How to execute shell scrips without creating files

How is it possible to execute a shell script without creating a file? For example assume I have the following script (testscript): #!/bin/bash function run_free() { free -m } run_free I then of ...
0 votes
2 answers
583 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
1 answer
540 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 ...
19 votes
7 answers
33k 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@...
0 votes
2 answers
3k views

Parallelize curl requests

This is my shell script: for i in `seq 1 $1`; do filename=randomfile$(uuidgen).txt head -c $2 </dev/urandom > $filename checksum256=$(sha256sum $filename | awk '{ print $1 }') ...
0 votes
1 answer
3k 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 \ &&...
27 votes
9 answers
55k 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
0 answers
68 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 #...
1 vote
1 answer
529 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
3k views

script run through jenkins user gets killed

In our jenkins build configuration we have the following shell commands (Execute shell) as the last step of our build process. echo "$USER" echo "Script executed from: ${PWD}" git submodule update --...
0 votes
1 answer
122 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 ...
3 votes
2 answers
2k views

Using Gentoo's `ebegin`, `eend` etc under Ubuntu

We're quite fond of the style of the ebegin, eend, eerror, eindent etc commands used by Portage and other tools on Gentoo. The green-yellow-red bullets and standard layout make for very quick spotting ...
1 vote
1 answer
41 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 ...
48 votes
6 answers
52k 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-...
0 votes
2 answers
3k views

Exit code for ldap testing using nc or ncat

I am trying to write shell script to test if a server is able to reach a specified ip and port. The commands i am using: ncat -w 5 <IP> 636 or 389 > /dev/null 2>&1 < /dev/null | ...
1 vote
1 answer
448 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 ...
6 votes
4 answers
3k 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
0 answers
70 views

Need help to Split the below HTML text file in two parts using linux scripting

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
2 answers
1k views

shell scripting with expect and a complex command line: no such file or directory

I'm trying to make this work #!/usr/bin/expect spawn "(psql blabla \"blabla sql;\" &> /dev/null) && (pg_restore -d xx my_file.sql &> /dev/null)" expect "Password for user ...
0 votes
2 answers
3k views

Script for search string inside the file for every one hour

I need to write a script where the particular string(alphanumeric) should be searched inside the file with every hour for whole day. And the search should not contain the previous hour results. Time ...
1 vote
1 answer
2k views

How to escape double quotes and exclamation mark in password?

I have the following code: curl -s --insecure -H "Content-Type: application/json" -X POST -d "{\"username\":\"$1\",\"password\":\"$2\"}" http://apiurl In the above curl command I want to escape the "...
2 votes
1 answer
2k views

Running Shell Script without a Password Prompt

I have a shell script that runs on a freebsd OS. the script has some commands that needs the sudo privileges Im excuting the script remotley and it's skipping the sudo commands i tried the following : ...
0 votes
3 answers
3k views

Moving files using sftp

I am trying to move files from one location to another on the remote server using sftp below: for i in a b c d do sftp $REMUSR <<EOM>>$OUT 2>&1 rename $SOURDIR/sample_${i}_[0-9][0-...
1 vote
1 answer
4k 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
26 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:...

1
2 3 4 5
13