'mkdir: cannot create directory: No such file or directory - cifs windows shared folder
I have a linux box here that i've set up with a cifs shared folder to my windows computer. No issues there, it works exactly as intended. However, i thought about running some bash scripts using that same directory and it seems like it's not finding my root.
now=$(date +"%Y-%m-%d")
#or: `now=$(date +%s)` if you back up more than once a day
mkdir /__backup/"$now"
Doing this from the shared folder brings up that it cannot find directory runningthese commands:
echo "$0"
dirname "$0"
shows the address as "."
Does anyone have any ideas on how to get this to run?
Solution 1:[1]
You are doing:
#!/bin/bash
now=`date "+%Y-%m-%d"`
mkdir "/__backup/$now"
So this only works if /__backup/ exists. Do:
#!/bin/bash
now=`date "+%Y-%m-%d"`
mkdir -p "/__backup/$now" # -p creates parent directories as needed (see man mkdir)
#Optional: change directory to the one you just created:
cd /__backup/$now
Of course, you will need root to make a directory in /, so you might want to check for that.
if [ `whoami` = "root" ]; then
# You are root...
else
echo "Error: Only root can do that."
exit 1
fi
You can avoid the whole problem of needing root if you create __backup in ~. You might also want to hide __backup by renaming it to .backup.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
