Kamis, 20 Februari 2014

Mengamankan Bash Script dengan Python Script

Contoh Python Script untuk mengamankan Bash Shell Script agar tidak diubah, contohnya bash script untuk backup, eksekusi yang menyimpan password (selanjutnya file python dapat dicompile untuk menghasilkan .pyc)
import tempfile
import subprocess

script_one = '''\
echo "Hello world!"
echo "This is a bash script. :-)"
'''

def run_script(script):
    with tempfile.NamedTemporaryFile() as scriptfile:
        scriptfile.write(script)
        scriptfile.flush()
        subprocess.call(['/bin/bash', scriptfile.name])
        print('temporary file' + scriptfile.name)

run_script(script_one)

Tidak ada komentar:

Posting Komentar