Cara Cepat Menghapus Folder Besar Berisi Banyak File di Linux
Tutorial ini menjelaskan bagaimana cara menghapus folder berukuran besar yang di dalamnya banyak file kecil-kecil di sistem operasi Linux. Read more
Tutorial ini menjelaskan bagaimana cara menghapus folder berukuran besar yang di dalamnya banyak file kecil-kecil di sistem operasi Linux. Read more
Sekedar catatan pada pemrograman bash bahwa pendefinisian variabel array dan menampilkan array adalah sebagai berikut ini : Read more
Berikut ini adalah contoh bash script script perbandingan if elif else multiple or multiple and gabungan antara and dan or membandingkan angka dan string :
Kadang kita mengeksekusi script bash melalui cron setiap menit sedangkan script tersebut belum menyelesaikan tugasnya. Yang terjadi script berjalan duplikat dan berkali-kali.
Berikut ini adalah contoh script yang bisa anda gunakan untuk mendeteksi script yang sudah berjalan.
#!/bin/sh
proses=`ps aux | grep namafile.sh | grep -v grep | wc -l`
if [[ $proses -gt 2 ]]; then
echo "script sudah jalan";
exit;
fi
Untuk mengujinya silahkan buat misalnya testrun.sh dan dibawahnya tambahkan sleep 30 dengan tujuan agar script tersebut selesai setelah 30 detik.
kira-kira seperti ini
#!/bin/sh
proses=`ps aux | grep testrun.sh | grep -v grep | wc -l`
if [[ $proses -gt 2 ]]; then
echo "script sudah jalan";
exit;
fi
#menguji sleep 30 second
sleep 30;
Bukalah beberapa window bash dan jalankan script testrun.sh secara bersamaan, maka yang anda dapatkan adalah sebagai berikut :
[root@script]# ./testrun.sh script sudah jalan
Pertanyaan yang mungkin muncul adalah mengapa -gt adalah 2 dan bukan 1?
Adapun perhitungannya adalah sebagai berikut :
Ketika testrun.sh berjalan maka terhitung 1 kemudian melakukan pengecekan ps aux dan apabila nilainya 1 maka script yg sedang dijalankan tersebut dianggap telah berjalan dan keluar output “script telah berjalan” yang sebenarnya tidak ada script lain yg berjalan kecuali proses yang saat itu dilakukan.
Demikian dan selamat mencoba.
Berikut ini adalah kumpulan bash script kalkulasi waktu dan tanggal dengan output jam detik dan menit:
Kalkulasi 2 waktu output dalam jam menit dan detik
START=$(date +%s);
sleep 1; # Your stuff
END=$(date +%s);
echo $((END-START)) | awk '{printf "%d:%02d:%02d", $1/3600, ($1/60)%60, $1%60}'
untuk contoh script lainya menyusul.
Bagaimana cara menghapus spasi dan baris kosong pada file menggunakan bash script ?
Menghapus baris kosong.
[root@]# cat file.txt satu dua tiga empat [root@]# sed -i '/^$/d' file.txt [root@]# cat file.txt satu dua tiga empat
Menghapus Spasi
[root@script]# cat file.txt satu lima dua puluh tiga ratus empat ribu [root@script]# cat file.txt | tr -d "[:blank:]" satulima duapuluh tigaratus empatribu
Menghapus Spasi dan New Line
[root@script]# cat file.txt satu lima dua puluh tiga ratus empat ribu [root@script]# cat file.txt | tr -d "[:space:]" satulimaduapuluhtigaratusempatribu[root@uvcms1 script]#
Menghapus new line saja
[root@script]# cat file.txt satu lima dua puluh tiga ratus empat ribu [root@uvcms1 script]# cat file.txt | tr -d "\t\n\r" satu limadua puluhtiga ratusempat ribu[root@script]#
Selamat mencoba.
This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.
Accept settingsHide notification onlySettingsWe may request cookies to be set on your device. We use cookies to let us know when you visit our websites, how you interact with us, to enrich your user experience, and to customize your relationship with our website.
Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.
These cookies are strictly necessary to provide you with services available through our website and to use some of its features.
Because these cookies are strictly necessary to deliver the website, refusing them will have impact how our site functions. You always can block or delete cookies by changing your browser settings and force blocking all cookies on this website. But this will always prompt you to accept/refuse cookies when revisiting our site.
We fully respect if you want to refuse cookies but to avoid asking you again and again kindly allow us to store a cookie for that. You are free to opt out any time or opt in for other cookies to get a better experience. If you refuse cookies we will remove all set cookies in our domain.
We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.
We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.
Google Webfont Settings:
Google Map Settings:
Google reCaptcha Settings:
Vimeo and Youtube video embeds:
