Check in bash that my system has time synchronized with ntpd

I implements a script that checks every half hour that my server has time correctly synchronized with ntpd, since there is an external process that sometimes blocks and changes the system time.

The first solution that has come to my mind is:

#! / bin / bash

#BORRAMOS LOG PREVIOUS
rm -f /root/sync_ntpd/control_restart_ntpd.log
rm -f /root/sync_ntpd/control_ntpd.log

CONTROL VARIABLES #DECLARO
control = 0
failure = 1

# We prove that the log does not contain failures during reboot
while [[ $control -lt 3 ]]&& [[ $fallo -eq 1 ]]make
control = $ (control + 1))
service ntpd restart >> /root/sync_ntpd/control_ntpd.log
echo "Restart the NTPD service | Attempt $ $ 2" check >> /root/sync_ntpd/control_restart_ntpd.log
echo "------------------------------------------------ - ">> /root/sync_ntpd/control_restart_ntpd.log
by reading the line
make
if [[ $linea =~ "FAILED" ]]so
echo "Failed to restart the service" >> >> /root/sync_ntpd/control_restart_ntpd.log
echo "" >> /root/sync_ntpd/control_restart_ntpd.log
echo "" >> /root/sync_ntpd/control_restart_ntpd.log
rm -f /root/sync_ntpd/control_ntpd.log
d & # 39; other
failure = 0
fi
made < /root/sync_ntpd/control_ntpd.log
done
echo "Servicio reiniciado correctamente" >> /root/sync_ntpd/control_restart_ntpd.log
echo "" >> /root/sync_ntpd/control_restart_ntpd.log
echo "" >> /root/sync_ntpd/control_restart_ntpd.log

But I do not know if there is a way to check if the time is correctly synchronized so that, otherwise, the ntpd service restart.

bash – Help to replace an empty space with a backslash and empty space in a command variable Run Shell with Automator

I create a controller service that converts all files in a folder to a compressor preset by running the following shell script:

VAR = "/ Applications / Compressor.app / Content / MacOS / Compressor -batchname MyFirstBatch"
for d in "$ @"; make
filename = $ (base name "$ d")
fname = "$ (dirname" $ ​​d ")" / "$ {filename%. *}"
VAR + = "-jobpath" $ d "-settingpath /Applications/Compressor.app/Contents/Resources/Settings/ProRes/proResHQName.setting -locationpath" $ fname ".mov"
completed
eval $ VAR

The problem is that the resulting paths in the chain have a empty space instead of backslash and empty spaceso I want to replace every "" in the re variable with a "".

In addition, is there a way to omit folders and only consider files?

Thank you.

Here is a screenshot of my workflow (Get Specified Finder Items and Get Folder Contents are only for testing purposes, I disable them when I use it as a service) :

Screen capture of the Automator service

ssh – Problem with SFTP after conversion from sh to bash when connecting

After SSH has entered the Android box (the SSHDroid application provides the host), I followed the psyincerise response (the last one listed) in How to set bash as the default shell ?. This allowed me to connect directly to bash but it broke SFTP. After the prompt for the password, it hangs. Can this be corrected with this solution?

Moreover, now the root ~ is / (~ was /data/data/berserker.android.apps.sshdroid/home) and it does not load /.bashrc automatically (it must be called as # source /.bashrc)

utc 15h06 pwd: /
! 67 root @ OnePlus # ls -al
total 5624
drwxr-xr-x 22 root root 0 2019-07-03 10:37.
drwxr-xr-x 22 root root 0 2019-07-03 10:37 ..
-rw-r - r-- 1 root root 268 2019-07-03 10:44 .bash_aliases
-rw ------- 1 root root 483 2019-07-03 10:37 .bash_history
-rw-r - r-- 1 root root 988 2019-07-03 10:51 .bashrc

I'm obviously not happy to put files in / but when the only tool you have is a hammer …

Bash Script – the new file belongs to the user with whom the script was created

a question i'm building a bash script that creates a log is running, but how can i make that new file belongs to the user with whom the script was created?

I've tried using chown – reference unsuccessfully

bash – How grep line ONLY before and above my line?

How grep lines only one or two before and above my line, I use

    grep --color = always -Irn -E & # 39; foo | bar & # 39;

but he finds me lines throughout the document:

foo.md:10:foo
foo.md:142:bar

I only need one coincidence of nearby lines, one or maybe two.

foo.md:10:foo
foo.md:12:bar

Something like that.

What is the difference between () and {} in bash for grouping outputs and commands

Here, only the second echo feeds the grep.

$ echo a1; echo a2 | grep -o a
a1
a

Here, both echoes do it.

$ {echo a1; echo a2;} | grep -o a
a
a

Here too.

$ (echo a1; echo a2) | grep -o a
a
a

So, what is the difference between () and {}?

shell script – How to shorten a list of variable names in bash?

In a shell script, I have a list of variables that I ordered in the form $ a, $ b, $ c, and so on. I would like to print these variables without having to list all the variables. My current code is:

a = 1
b = 2
c = 3
d = 4
e = 5
f = 6
g = 7

for x in $ a $ b $ c $ d $ e $ f $ g
make
echo "$ x"
completed

Can I shorten $ a $ b $ c $ d $ e $ f $ g into an item referring to $ a to $ g?

My bash script ends but it's not finished

I've created a little script to find raspberry on a local network and try the default login.

I do not understand why the script does not continue running

there is the script: https://pastebin.com/CNVepNEU

there is the exit:

SCAN for RPi on 192.168.1.0/24

List of exposed ssh servers:

192.168.1.43

192.168.1.101

192.168.1.254


TRY FAULT LOGIN FOR RPi

check for 192.168.1.43

192.168.1.43 is vulnerable !!!

leave loop


PWNED RPi:

192.168.1.43

sorry for my english i'm french

an idea ?

BASH Script to find the latest files and delete them

I have database backup files and I would like to create bash-script that returns different names from the most recent files in the current directory. For example:

/ home / user / toto /
a_1.0
a_1.1
b_1.0
b_1.1
c_1.0
c_1.1

I want the script output to look like this:

/ home / user / toto /
a_1.1
b_1.1
c_1.1

I read a reference from here and I was able to get the above result with this sample command:

#! / bin / bash
find . -name "a_ *" -print0 | xargs -r -0 ls -t | head -1
find . -name "b_ *" -print0 | xargs -r -0 ls -t | head -1
find . -name "c_ *" -print0 | xargs -r -0 ls -t | head -1

I just changed the name template to the name of the different backup file, but how to delete all the files except for the file printed in the result above?

sudo – -bash: echo: write error: invalid argument

I have an Intel upboard motherboard and I want to use its gpio pins. To do this, I try first below the code:

echo 17> sys / class / gpio / export

but when I run this, I take this mistake

-bash: echo: write error: invalid argument

I looked for this error in many pages and tried the suggested solutions but it did not work. What can be the problem and how can I solve it?