Assignment No 1
Assignment No 1
3. Write a shell script that backs up a directory and logs the disk
usage before and after the backup.
Ans. src_dir="/path/to/source"
dest_dir="/path/to/destination"
log_file="backup_log.txt"
echo "Backup started at $(date)" >> $log_file
echo "Disk usage before backup:" >> $log_file
df -h >> $log_file
cp -r $src_dir $dest_dir
echo "Backup completed at $(date)" >> $log_file
echo "Disk usage after backup:" >> $log_file
df -h >> $log_file
echo "Backup and logging completed."
4. Write a Python script that calls a shell script to compress a
directory and then lists the contents of the compressed file.s
Ans. import subprocess
import os
subprocess.call(['./compress_dir.sh'])
compressed_file = 'compressed_dir.tar.gz'
subprocess.call(['tar', '-tzf', compressed_file])