Bash script error trying to write to file: no such file or directory
4
votes
1
answer
19610
views
I'm getting an error with a very simple script. The script should run pg_dumpall and write the output to a file but I'm getting an error that the resulting file doesn't exist. I know it doesn't exist, thats why I want to creat it! :-/
#!/bin/bash
#remove previous day's dump and create new
rm -f /home/user/db_dump_*.txt;
pg_dumpall -U postgres -w > /home/user/db_dump_
date '+%d/%m/%Y_%H:%M:%S'
.txt;
The result is:
db_dump.sh: line 4: /home/user/db_dump_12/02/2017_14:30:15.txt: No such file or directory
The date command is working fine and the filename comes out perfect but instead of the file being created, I get the error saying that it doesn't exist. I'm running the script as root so there should be no issues with permissions. I can write to the user's home directory without any problems.
Any ideas?
Asked by rijo79
(75 rep)
Feb 12, 2017, 08:15 PM
Last activity: Mar 14, 2021, 09:12 PM
Last activity: Mar 14, 2021, 09:12 PM