Questions tagged as ['bash']

Bash is the Bourne Again SHell, the successor to the classic Unix sh (shell).
Score: 0
treatments of /var/log/messages with rsyslog
in flag

I having problems with my /var/log/messages file. Indeed, I collect logs from different network switches on my server and their logs go in a special file + the messages file. I would like the switch logs to go only to the specific file and not to the /var/log/messages file. Do you know how to please? I am on RedHat 7.

Here is my configuration on /etc/rsyslog.d/test.conf

$template syslog,"/var/log/clie ...
Score: 0
How to use a screen with bash script?
ng flag

I tried to create an executable .sh file with command that create screen like this:

screen -dmS ast [comand]

And let my crontab execute it like this

* * * * * bash /root/my_bash.sh

But nothing executed, but with normal console command bash /root/my_bash.sh it's working successfully.

How can I fix it?

Score: 0
Removing old files from home directories
mz flag

I need to find and remove files older than 2 weeks from the home directories of my cluster. I do not want to let people just "touch" the file to change the modification date and keep it for another 2 weeks. (I'm talking about files of several hundreds of Gb) I thought about doing md5 check on the content and comparing it against a list with the file creation date, but maybe there is an easier solution.

Score: 0
Thomas P avatar
How to delete files in destination folder that are already present in source folder
br flag

I got two folders, a source S with files (and subfolders and so on):

  • a.txt
  • b.txt
  • c.txt
  • ...

and a destination folder D with files:

  • a.txt
  • b.txt
  • b1.txt
  • c.txt
  • c2.txt
  • ...

and I want to delete all files in D that are already present in S, so that D contains just files that are not present in S.

Any ideas, how I can achieve this with standard tools (rsync, robocopy, ...)?

P.S.: In real world S is abo ...

Score: 0
Ress avatar
Zip all files returned from "grep-ril" command
lc flag

I'm using grep -ril to be able to see all files that contain a certain string:

[user@machine]$ grep -ril "test string"
file1.log
file2.log
file3.log
file4.log
...

I then would like to zip all of the files that have been returned by that command. Is this possible?

I've tried things such as grep -ril myPattern | zip files.zip and grep -ril myPattern | zip > files.zip but nothing has worked so f ...

Score: 1
Curl Command Send Asynchronous Request
sx flag

I using this curl request for sending data to API :

curl --location --request POST 'MY_IP' \
--header 'Content-Type: text/plain' \
--data-raw ' [{
    "event_id": "123",
}]    
'

I want to check the API performance by sending request asynchronously and measure the time take I tried to use xargs -P 10 which say send 10 request parallel but not able to do so ? Any help and how I can measure time ?

Score: 0
FlexMcMurphy avatar
rsync : write failed - No space left on device (28) despite using --inplace
kr flag

I am using a script to make a backup of a running Debian Stretch based Linux Distro (NextCloudPi)

The method in the script that does the backup uses rsync.

backup()
{
  mntimg
  sync
  rsync -aDH --partial --numeric-ids --delete --force --exclude "${MNTPATH}" --exclude '/dev' --exclude '/lost+found' --exclude '/media' --exclude '/mnt' \
--exclude '/proc' --exclude '/run' --exclude '/sys' --exclude '/t ...
Score: 0
vik2595 avatar
Ansible playbook rebooting the server , wait till reboot complete
us flag

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: Handle reboot
  hosts: all
  become: yes
  
  tasks:
    - name: Execute the script 
      shell: bash testscript.sh
      args:
        chdir: /home/ubuntu
      notify:
        - Wait for server to restart
 ...
Score: 0
Damola avatar
Locate and Move files to a destination
ch flag

I intend to locate some files matching a certain pattern. After the files have been located, i want to move them to a new directory.

for i in $(find <search_location> -name '<search_pattern>')
do
    #mkdir -p <new_location_to_be_copied_to>
    mv $i <new_location_to_be_copied_to>
done

Can the above code achieve that. Any better way to achieve that?


UPDATE

After Executing the  ...

Score: 1
Using URL's with special characters in nginx maps
in flag

When using nginx and maps it is possible to rewrite mutiple URL's with a map file. What is problematic is when the URL contains special characters. I have been breaking my head trying to get this right, and hope this Question / Solution might save others from becoming gray hair.

Let's set the scenario.

A Linux server (Debian/Ubuntu) running standard nginx. DNS pointing to this server that resolves ...

Score: 0
Petr Javorik avatar
rsync over multiplexed SSH connection and multiple jumphosts
id flag

I need to rsync a file from remote hosts to my local machine over multiple jumphosts. I'd like to use shared SSH connections so that I don't have to submit 2FA multiple times at some jumphosts.

The idea is I create a master connection

ssh user@jumphost01

then other connections

ssh -J user@jumphost01,user@jumphost02 root@target01
...

Shared connections control files in ~/.ssh/ look as follows

co ...
Score: 1
How to do sudo grep in a bash script?
in flag

I would like to check if the given ip address is already in the config file. But /etc/ can only be accessed by root, and I'm running the a script as admin. It seems I can't just do sudo

#!/bin/bash
CLIENT_WG_IPV4="10.66.66.1"

DOT_EXISTS=$(sudo grep -c "$CLIENT_WG_IPV4/22" "/etc/wireguard/wg0.conf")
if [[ ${DOT_EXISTS} == '0' ]]; then
   ...
fi

I get the error message:

grep: /etc/wireguard/wg0.conf: P ...

Score: 1
Always Sunny avatar
Sending email with ssmtp From value issue
pk flag

I am trying to send an email from my cron script using ssmtp, the email is working fine but the "From" value is always showing Ubuntu <ubuntu@example.com> which I don't want to use because I need to use something like From="Cron Report <no-reply@example.com>",

ssmtp.conf

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disabl ...
Score: 0
Craig avatar
sed works fine from interactive shell but not from script
de flag

Trying to enable/disable xdebug on my php-fpm docker container.

If I start an interactive shell using docker exec my_container bash then run:

sed -i 's/^#zend_extension/zend_extension/' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

or

sed -i 's/^zend_extension/#zend_extension/' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

The file /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini h ...

Score: 0
Trying to partition aws linux server using shell script
cn flag

When I created Amazon linux server(similar to Centos 7). I had these partitions I am trying to create partitions using shell script lsblk gives me following information

NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1       259:0    0  80G  0 disk
├─nvme0n1p1   259:1    0  80G  0 part /

I have tried directly modifying fstab file and rebooting, that didnt help. Maybe I was doing something w ...

Score: 0
nick avatar
script on changing directory ownership via bash
cn flag

I am trying to find directories older than 150 days and change their ownership as root. Please can you advice on how do i fix the below pls?

find /mnt/mailfolder/ -maxdepth 1 -type d -mtime +150 -printf "%P\n" -exec "chown -R oracle:oinstall {}"

Score: -1
Georgi Koemdzhiev avatar
systemd script do not set correct file permissions at boot time
cn flag

I have written a simple service that calls a bash script that should change file permissions at boot time. The issue is that it seems that the service is not working as the permissions are not changed by the time the user logs in.

However, when I run the service manually - sudo systemctl start setpermissions.service it works and the file permissions are set correctly.

This are the file permission ...

Score: 0
In Linux/bash how can I prevent asynchronous commands?
vn flag

I have a makefile that calls external build scripts.

Some of these scripts (which I can't change) make use of commands that are forked / backgrounded (or asynchronous as the bash manual names them)

That means that the next line in the makefile can start before some of the previous command finishes - creating a race condition.

I somehow need to either wait on the forked process and all it's children, or ...

Score: 0
nipy avatar
Add curl command to function for bash profile
br flag

How do I add this command as an alias or function to my bash_profile?

curl -X GET -H "x-api-key:xxxxxxxxxxxxxx" -H "Content-Type: application/json"  https://xxxxxxx.amazonaws.com/api/ | jq

I tried this:

my-func () { curl -X GET -H "x-api-key:xxxxxxxxxxxxxx" -H "Content-Type: application/json"  https://xxxxxxx.amazonaws.com/api/ | jq; }

I get the following error when trying to add as an alias or use  ...

Score: 0
ansible-playbook: command not found when running bash with cron
cn flag

Running on ubuntu18, have a bash job to collect data from a router using ansible. Here is the bash script

#!/bin/bash
cd ~/datacollect
ansible-playbook -i /home/user/datacollect/hosts /home/user/datacollect/datacollect.yml

If I run the bash job from ubuntu console, there is no issue. Since we need to collect data every 5 minutes, I created a cron job for it.

* * * * *  /home/user/datacollect/call ...
Score: 0
Byte legion avatar
Postfix After-Queue Content Filter full example
de flag

i'm trying the Simple content filter example: i followed the steps mentioned here http://www.postfix.org/FILTER_README.html#simple_filter

but in line 24 of the content filter that can be a simple shell script like this

you need to specify your content filter

my question is :

is there any full example with a content filter ( line 24) that i can work with ?

 1 #!/bin/sh
 2 
 3 # Simple shell-based fi ...
Score: 0
trailing "-" as a placeholder
jp flag

If reading this I then understanding, that you can set the stdin to be piped to the command as parameter to a placeholder "-"

like:

cat <<EOF | printf -  
hello  
new line
EOF

But it only prints "%"?

Score: 0
Jeriko avatar
Delaying my own process to automount an external storage which start at boot
cn flag

I would like to implement my own process into a CentOS7 operating system which automount an external storage (AVID ISIS for this example) at boot through systemd.

To do that, I scripted the mount procedure (because I cannot use fstab in this particular case, the avidfos command provided by AVID is needed) but I have noticed that my process failed at boot. When I run it just after the boot process ...

Score: 0
jcmd works in console but fails in script
in flag

I'm getting mad with what should be a simple task: a java process is running, runs out of memory and a script runs.

SELinux is disabled.

in setenv.sh :

-XX:OnOutOfMemoryError='/opt/alfresco/scripts/dumpNrestart.sh > /tmp/dumpNrestart.log 2>&1'

in /etc/sudoers.d/alfresco_sudoers :
%alfresco ALL= NOPASSWD: /opt/alfresco/java/bin/jcmd

in dumpNrestart.sh :
#!/bin/sh -x
PIDDE=$(cat /opt/alfre ...
Score: 0
Sidd avatar
Not able to access groovy variable inside shell script in JenkinsFile
cn flag
def NAMESPACE = "Dev"

def BODY= sh(
script:'''body=$(cat <<-EOF
{
    "name": "${NAMESPACE}",
    "type": "regularwebapp"
}
EOF
)
(echo $body)''',
returnStdout: true
).trim()

The above doesnt work, output is as follows:

{
    "name": "",
    "type": "regularwebapp"
}
Score: -2
Michael Altfield avatar
Programatically get full path to binary in powershell (which, where, Get-Command)
cn flag

How do I get the absolute path to a given binary and store it to a variable?

What is the equivalent to the following for Linux Bash in Windows Powershell?

user@disp985:~$ path=`which gpg`
user@disp985:~$ echo $path
/usr/bin/gpg
user@disp985:~$ 

user@disp985:~$ $path
gpg: keybox '/home/user/.gnupg/pubring.kbx' created
gpg: WARNING: no command supplied.  Trying to guess what you mean ...
gpg: Go ahead  ...
Score: 1
Rajarshi Das avatar
How to get extra vars java link and download it in ansible and extract it
in flag

I want to download java from http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz

then extract it

tar -xzvf jdk-8u131-linux-x64.tar.gz

but not able to do it

I have the below ansible playbook code

- name: Download Java to Latest Version
      shell: |
              mkdir /opt/java
              cd /opt/java
              wget -c --header "C ...
Score: 0
Why is this bash script triggering so many false positives for monitoring memory usage?
fi flag

I am monitoring hundreds of servers both dedicated and virtual using the following script:

#!/bin/bash

PATH=/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin

threshold=90

serverip=$($(which ifconfig) | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -1)
memused=$(free | awk '/Mem/{printf("R ...
Score: 0
Syntax check for bash script, with error code as exit code for the sake of SSH?
cn flag

I want to automate some deployment steps. Have CD server, it runs on Linux (in bash). Project is then configured to run bash script on actual app server to perform deployment. SSH is used to connect from CD runner to actual server.

Whole setup relies on an assumption that failing deployment is signaled by appropriate non zero exit code.

Want to add extra safety, so that syntax errors stop/fail deplo ...

Score: 0
Mhd avatar
command that cannot work in background (asterisk)
ru flag
Mhd

am trying to run script in background which contain command such like "asterisk -rvd >> xyz.log", when I run it directly it work well but when run it with any background way (service, cron, &, nohub,,) it stop directly with this message: stopped

so what is the prober way to run this command at background ?