Cara Menggunakan eval di Linux Bash Script

  • Post author:
  • Post category:Tutorial

Dari semua perintah Bash, eval lama yang malang mungkin memiliki reputasi terburuk. Dibenarkan, atau hanya pers yang buruk? Kami membahas penggunaan dan bahaya dari perintah Linux yang paling tidak disukai ini.

Kita Perlu Bicara Tentang eval

Digunakan secara sembarangan, eval dapat menyebabkan perilaku yang tidak terduga dan bahkan ketidakamanan sistem. Dari suaranya, kita mungkin tidak boleh menggunakannya, kan? Yah tidak cukup. (more…)

Continue ReadingCara Menggunakan eval di Linux Bash Script

Belajar Linux: Mengetahui perintah/command favorit anda di Shell

Saya termasuk pengguna linux yang cukup sering memakai shell baik via Terminal maupun Konsole. Apakah anda juga? Nah, berikut adalah perintah-perintah (command) yang paling sering saya gunakan di shell Linux:

57 clear
49 sudo
32 cd
25 ls
13 youtube-dl
10 VBoxManage
7 ./winetricks
7 ping (more…)

Continue ReadingBelajar Linux: Mengetahui perintah/command favorit anda di Shell

Belajar Bash: for Loop

The purpose of this exercise is to write a number of for loops to be able to understand how to implement them effectively.

1. Create a script called defense.sh in /opt/scripts
The purpose of the script is to configure the firewall to drop known zombie networks.
[sourcecode language=”bash”]
#!/bin/bash
IP=/opt/scripts/banned

for i in $(awk ‘{print}’ < "$IP" )
do
echo $i
iptables -A INPUT -p tcp -s $i -j DROP
done
exit 0
[/sourcecode]

The script takes a list of IP Addresses in a file and uses awk to print each IP from the file into the variable $i. Then an iptables command employs the “$i” variable to drop each of the IP Addresses on the INPUT chain. The “-p tcp” limits the drop to TCP protocol and the “-s” indicates the source. The IP is dropped with the jump “-j” to DROP. (more…)

Continue ReadingBelajar Bash: for Loop

Belajar Bash: Until Loop

The until loop will continue until a specific requirement is met or  as long as the exit status is NOT zero.  This is the opposite of the while loop.

In the example below you can see that the variable “i” starts with 0 and will loop until it equals 100.  It is incremented by one each loop.  When it reaches 100 it will deliver the zero as an indication of success and the loop will stop. (more…)

Continue ReadingBelajar Bash: Until Loop

Turn on Bash Smart Completion

The Bash shell has this sweet feature where you can use the TAB key to auto-complete certain things. For example, when I am in my home directory, the following command:
$cd Do[TAB-key]
will automatically yield:
$cd Documents

Though you can use the TAB key to complete the names of files and directories, by default the completion is pretty “dumb”. If you have already typed$cd Dyou would expect that the tab key would cause only the directory names to be completed, but if I try it on my machine, the tab completion tool uses filenames too. (more…)

Continue ReadingTurn on Bash Smart Completion

Belajar Linux: Searching file di Linux Shell

Mencari file di Linux merupakan pekerjaan yang gampang jika anda menggunakan tool-tool yang sudah ada dan berbasis GUI, hampir semua File Manager (contoh: Nautilus, Dolphin, Thunar, PCManFM dll) sudah mempunyai fitur pencarian berkas. Namun bagaimana halnya jika anda bekerja di server dg tanpa GUI dan cukup dengan akses SSH Shell?

Ada beberapa command bawaan yang bisa kita gunakan diarea Terminal/Konsole untuk mencari berkas:

whereis

whereis khusus digunakan untuk mencari file binary, source dan manual page. penggunaanya cukup dengan perintah whereis namaprogram (more…)

Continue ReadingBelajar Linux: Searching file di Linux Shell