Questions tagged as ['bash']

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 ...

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?

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.
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 ...
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 ...

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 ?
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 ...
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
...
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 ...

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 ...
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 ...

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 ...
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 ...
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 ...

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 ...
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 {}"
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 ...

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 ...
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 ...

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 ...
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 ...

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 "%"?
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 ...

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 ...
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"
}
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 ...
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 ...

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 ...

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 ...
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 ?