Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function choosefile {
- # ask filename
- echo "Choose a file name to work with and press enter"
- read file
- echo " "
- echo "We will work with $file "
- echo " "
- }
- function createfile {
- echo "create $file"
- touch $file
- }
- function deletefile {
- echo "delete $file"
- rm $file
- }
- function addpermition {
- echo "Enter R to give read permition, W for write, X to execute ?"
- select i in R W X; do
- if [ "$i" = "R" ]; then
- echo "give read permition on $file"
- break
- elif [ "$i" = "W" ]; then
- echo "give write permition on $file"
- break
- elif [ "$i" = "X" ]; then
- echo "give execute permition on $file"
- break
- else
- echo "Bad choice"
- fi
- done
- echo "chown $user $file"
- }
- function edit {
- nano $file
- }
- function backup {
- date=$(date '+%Y-%m-%d-%H_%M_%S')
- echo "Create backup of $file to $file-backup-$date"
- cp -p $file $file-backup-$date
- }
- function restore {
- # List backups of $file
- $backup="Please select a backup to restore:"
- options=( $(find . -name "*$file-backup*" -maxdepth 1 -print0 | xargs -0) )
- # create menu to permit to select file to restore
- PS3="$backup "
- select opt in "${options[@]}" "Quit" ; do
- if (( REPLY == 1 + ${#options[@]} )) ; then
- exit
- elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
- echo "You choose $opt which is file $REPLY"
- break
- else
- echo "Bad selection"
- fi
- done
- # copy backup
- cp -v $opt $file
- echo "$opt restored on $file"
- }
- function displaysize {
- echo "Size of $file: "
- ls -s $file
- }
- function findfile {
- echo "Look for $file on current directory"
- find . -name "$file"
- }
- choosefile
- PS3="Make a choice: (press enter to display menu) "
- select item in "- Create the file" "- Delete the file" "- Edit the file" "- Create a backup " "- Restore a backup " "- display size " "- Add permition " "- Find file " "- Exit script " "- Change file"
- do
- for var in $REPLY; do
- echo "Your choice: $var : $item"
- case $var in
- 1)
- # call createfile function
- createfile
- ;;
- 2)
- # call deletefile function
- deletefile
- ;;
- 3)
- # call deletefile function
- edit
- ;;
- 4)
- # call deletefile function
- backup
- ;;
- 5)
- # call deletefile function
- restore
- ;;
- 6)
- # call deletefile function
- displaysize
- ;;
- 7)
- # call deletefile function
- addpermition
- ;;
- 8)
- # call deletefile function
- findfile
- ;;
- 9)
- echo "End of script"
- exit 0
- ;;
- 10)
- choosefile
- ;;
- *)
- echo "Incorrect selection"
- ;;
- esac
- done
- done
- #création, manipulation, droits d'accès, sauvegarde, tri, recherche
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement