variables | binary ASCII | loop parallel running | source
source is a bash shell built-in command that executes the content of the file passed as argument, in the current shell. It has a synonym in '.' (period).
------------------
Show file content with tabs (without line breaks and non-printing characters)
cat -T /tmp/testing.txt
Show file content with line breaks (without tabs and non-printing characters)
cat -E /tmp/testing.txt
Show file content with tabs, line breaks and non-printing characters
cat -A testfile
name^Isurname^Iage$
Bill^ISimson^I22$
Alex^IFerguson^I33$
------------------
$ mtr --report google.com
HOST: example Loss% Snt Last Avg Best Wrst StDev
1. inner-cake 0.0% 10 2.8 2.1 1.9 2.8 0.3
2. outer-cake 0.0% 10 3.2 2.6 2.4 3.2 0.3
3. 68.85.118.13 0.0% 10 9.8 12.2 8.7 18.2 3.0
4. po-20-ar01.absecon.nj.panjde 0.0% 10 10.2 10.4 8.9 14.2 1.6
5. be-30-crs01.audubon.nj.panjd 0.0% 10 10.8 12.2 10.1 16.6 1.7
6. pos-0-12-0-0-ar01.plainfield 0.0% 10 13.4 14.6 12.6 21.6 2.6
7. pos-0-6-0-0-cr01.newyork.ny. 0.0% 10 15.2 15.3 13.9 18.2 1.3
8. pos-0-4-0-0-pe01.111eighthav 0.0% 10 16.5 16.2 14.5 19.3 1.3
9. as15169-3.111eighthave.ny.ib 0.0% 10 16.0 17.1 14.2 27.7 3.9
10. 72.14.238.232 0.0% 10 19.1 22.0 13.9 43.3 11.1
11. 209.85.241.148 0.0% 10 15.1 16.2 14.8 20.2 1.6
12. lga15s02-in-f104.1e100.net 0.0% 10 15.6 16.9 15.2 20.6 1.7
------------------
cat pi
#!/bin/bash
for ip in 192.168.1.{1..25};
do
ping $ip -c 2 &>/dev/null;
if [ $? -eq 0 ];
then
echo "$ip OK"
fi
done
> file redirects stdout to file
1> file redirects stdout to file
2> file redirects stderr to file
&> file redirects stdout and stderr to file
x
------------------
To make the ping commands in parallel, enclose the loop body in ()&
#!/bin/bash
for ip in 192.168.1.{1..25};
do
(
ping $ip -c 2 &>/dev/null;
if [ $? -eq 0 ];
then
echo "$ip OK"
else
echo "$ip Not OK"
fi
)&
done
------------------------------
The "Binary" transfer mode of FTP copies files exactly, byte for byte. Simple and straightforward.
When bringing text files between different operating systems, though, this might not be what you want -- different operating systems use different codes to represent line breaks. The "ASCII" mode exists for this purpose: it automatically translates all line endings from the source system's format to the destination's.
Not sure about "Auto", but I imagine it looks that the file's extension or something similar to decide whether it's a text file, and tries to guess the appropriate mode.
------------------------------
If statements
https://linuxacademy.com/blog/linux/conditions-in-bash-scripting-if-statements/
------------------------------
Commands can be run on remote host:
ssh mec@192.168.0.1 “echo user: $(whoami)”
to run a command of the remote host and display its output on the localhost shell, use the following syntax:
ssh user@host ‘COMMANDS’
------------------------------
difference between $var and $(var)
echo user: $whoami
user:
$(whoami)
user: ubuntu
------------------------------
Mounting a remote drive at a local mount point
$ sshfs user@remotehost:/home/path /mnt/mountpoint
Password:
Now data at /home/path on the remote host can be accessed via a local mount point /mnt/mountpoint
In order to unmounts after completing the work use:
$ umount /mnt/mountpoint
------------------------------
------------------
Show file content with tabs (without line breaks and non-printing characters)
cat -T /tmp/testing.txt
Show file content with line breaks (without tabs and non-printing characters)
cat -E /tmp/testing.txt
Show file content with tabs, line breaks and non-printing characters
cat -A testfile
name^Isurname^Iage$
Bill^ISimson^I22$
Alex^IFerguson^I33$
------------------
$ mtr --report google.com
HOST: example Loss% Snt Last Avg Best Wrst StDev
1. inner-cake 0.0% 10 2.8 2.1 1.9 2.8 0.3
2. outer-cake 0.0% 10 3.2 2.6 2.4 3.2 0.3
3. 68.85.118.13 0.0% 10 9.8 12.2 8.7 18.2 3.0
4. po-20-ar01.absecon.nj.panjde 0.0% 10 10.2 10.4 8.9 14.2 1.6
5. be-30-crs01.audubon.nj.panjd 0.0% 10 10.8 12.2 10.1 16.6 1.7
6. pos-0-12-0-0-ar01.plainfield 0.0% 10 13.4 14.6 12.6 21.6 2.6
7. pos-0-6-0-0-cr01.newyork.ny. 0.0% 10 15.2 15.3 13.9 18.2 1.3
8. pos-0-4-0-0-pe01.111eighthav 0.0% 10 16.5 16.2 14.5 19.3 1.3
9. as15169-3.111eighthave.ny.ib 0.0% 10 16.0 17.1 14.2 27.7 3.9
10. 72.14.238.232 0.0% 10 19.1 22.0 13.9 43.3 11.1
11. 209.85.241.148 0.0% 10 15.1 16.2 14.8 20.2 1.6
12. lga15s02-in-f104.1e100.net 0.0% 10 15.6 16.9 15.2 20.6 1.7
------------------
cat pi
#!/bin/bash
for ip in 192.168.1.{1..25};
do
ping $ip -c 2 &>/dev/null;
if [ $? -eq 0 ];
then
echo "$ip OK"
fi
done
> file redirects stdout to file
1> file redirects stdout to file
2> file redirects stderr to file
&> file redirects stdout and stderr to file
x
------------------
To make the ping commands in parallel, enclose the loop body in ()&
#!/bin/bash
for ip in 192.168.1.{1..25};
do
(
ping $ip -c 2 &>/dev/null;
if [ $? -eq 0 ];
then
echo "$ip OK"
else
echo "$ip Not OK"
fi
)&
done
------------------------------
The "Binary" transfer mode of FTP copies files exactly, byte for byte. Simple and straightforward.
When bringing text files between different operating systems, though, this might not be what you want -- different operating systems use different codes to represent line breaks. The "ASCII" mode exists for this purpose: it automatically translates all line endings from the source system's format to the destination's.
Not sure about "Auto", but I imagine it looks that the file's extension or something similar to decide whether it's a text file, and tries to guess the appropriate mode.
------------------------------
If statements
https://linuxacademy.com/blog/linux/conditions-in-bash-scripting-if-statements/
------------------------------
Commands can be run on remote host:
ssh mec@192.168.0.1 “echo user: $(whoami)”
to run a command of the remote host and display its output on the localhost shell, use the following syntax:
ssh user@host ‘COMMANDS’
------------------------------
difference between $var and $(var)
echo user: $whoami
user:
$(whoami)
user: ubuntu
------------------------------
Mounting a remote drive at a local mount point
$ sshfs user@remotehost:/home/path /mnt/mountpoint
Password:
Now data at /home/path on the remote host can be accessed via a local mount point /mnt/mountpoint
In order to unmounts after completing the work use:
$ umount /mnt/mountpoint
------------------------------
Comments
Post a Comment