Note that there are some explanatory texts on larger screens.

plurals
  1. POLinux shell script : make a folder with the current date name
    primarykey
    data
    text
    <p>I am trying to make a simple backup script and i have problem creating a folder with the curent date for name</p> <p>My script is that and basically the problem is on the last line</p> <pre><code>drivers=$(ls /media/) declare -i c=0 for word in $drivers do echo "($c)$word" c=c+1 done read -n 1 drive echo c=0 for word in $drivers do if [ $c -eq $drive ] then backuppath="/media/$word/backup" fi c=c+1 done echo "doing back up to $backuppath" cp -r /home/stefanos/Programming $backuppath/$(date +%Y-%m-%d-%T) </code></pre> <p>Ouput:</p> <pre><code>(0)0362-BA96 (1)Data (2)Windows 0 doing back up to /media/0362-BA96/backup cp: cannot create directory `/media/0362-BA96/backup/2012-12-05-21:58:37': Invalid argument </code></pre> <p>The path is triply checked that is existing until /media/0362-BA96/</p> <p><strong>SOLVED</strong>: Did what janisz said the final script looks like </p> <pre><code>drivers=$(ls /media/) declare -i c=0 for word in $drivers do echo "($c)$word" c=c+1 done read -n 1 drive echo c=0 for word in $drivers do if [ $c -eq $drive ] then backuppath="/media/$word/backup" fi c=c+1 done echo "doing back up to $backuppath" backup(){ time_stamp=$(date +%Y_%m_%d_%H_%M_%S) mkdir -p "${backuppath}/${time_stamp}$1" cp -r "${1}" "${backuppath}/${time_stamp}$1" echo "backup complete in $1" } #####################The paths to backup#################### backup "/home/stefanos/Programming" backup "/home/stefanos/Android/Projects" backup "/home/stefanos/Dropbox" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload