Kamis, November 24, 2011

Javascript : Reload Target / Parent Window From Second Child Window

I have problem like this guy on this link.

Solution : use window.name, and target it to reload

On parent page :
window.name = "parent_window";

On the first child page :
function open2print(id_cek_in,diskon) {
 window.open( "cek_print.php?id_cek_in="+id_cek_in+"&cetak=y&diskon="+diskon, "print","status=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=600,height=800" )
}

On the second child page :
function reloadWin(){
 var parent_window = window.open("", "parent_window");
 parent_window.location.reload(true);
}

<body onload=reloadWin();>

So when the second child window load, it will be reload parent window.

Source : http://www.codingforums.com/showthread.php?t=113902


PS : I hate javascript, too many parents and children involved :(

Kamis, November 17, 2011

Bash : Auto Delete Old Backup Files

Based on my experience on maintenance project.
It's about to create auto delete old backup files on Mandriva 2005 (Linux) server.

This article is related with this article

After create backup file there will be alot of files created in our backup folder.
So we need an auto delete old backup files.

1. Create recycle.sh
$ mcedit /recycle.sh

File content :

#! /bin/sh
find /backup | grep `date -d '1 week ago' +%Y-%m-%d` | xargs --no-run-if-empty rm

2. Edit crontab

$ mcedit /etc/crontab

File Content :

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
00 15 * * 1-6 root /bin/sh /recycle.sh

3. Reconfigure your crontab

$ crontab -u[username] /etc/crontab
$ crontab -l

Auto delete scheduled every Monday through Friday 2 pm :)

Modified from : http://unix.stackexchange.com

Bash : Auto Backup Mysql on Mandriva 2005

Based on my experience on maintenance project.
It's about to create auto backup mysql on Mandriva 2005 (Linux) server.

1. Create file backup.sh, you may using mc or pico

$ mcedit /backup.sh

File content :

#! /bin/sh
/usr/bin/mysqldump -u[username] -p[password] [database_name] > /[your_backup_directory]/[filename].sql
cd /backup
tar --remove-files -czf backup-`date '+%Y-%m-%d' `.tar.gz -R *.sql
sudo cp -f *.tar.gz /[another_backup_directory]

2. Edit your cron list

$ mcedit /etc/crontab

File content :

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
00 7-14 * * 1-6 root /bin/sh /backup.sh

3. Reconfigure your crontab

$ crontab -u[username] /etc/crontab
$ crontab -l

MySQL auto backup scheduled every Monday through Friday beginning at 7 am till 2 pm :)