Hiiii,

here is my script--

:
BackupLocation="$OPTARG"
                if [[ $LFlag -eq 1 ]]; then
                        echo "Either option l or L should be given to $Programname"
                        echo "$Usage"
                        echo "$Programname is terminated"
                        return $ERR;
                fi
                if [[ $isBackUp -eq 1 ]];
                then
                        if [[ ! -d $BackupLocation ]];
                           then
                                echo "Non-existant directory specified"
                        fi
                               #givenPath="$BackupLocation"
                                BackupLocation=$BackupLocation/backup
                                mkdir -p $BackupLocation >/dev/null 2>&1
                                if [[ $? = 0 ]];
                                then
                                        echo "$Programname creates the dirctory $BackupLocation"
                                else
                                        echo "$Programname could not able to create the directory $BackupLocation"
                                        return $ERR
                                fi


                        lFlag=1
                        Llcron=l
                else
                        echo "$Programname is executed with -l option without action mtBackup"
                        echo "$Usage"
                        echo "$Programname is terminated"
                        return $ERR
                fi
                ;;

when i run this script through cronjob,then i am getting a directory creation problem.

supoose the directory name which i am giving is--

/home/namish
then my creates a directory called

/home/namish/backup

when i run it through cron then it again creates the directory backup inside backup directory.I can see my script is like that only but i want to modify this,can you please give me some valueable inputs so that this problem can be resolved.

The outcome should be when i run the script through cron it should not create the dir inside the backup di,instaed it should take backup onlyin the dir /home/namish/backup.If you need any moreclarification then please let me know.

Thanks..

remove -p from mkdir

remove -p from mkdir

Thanks Dima for paying attention.
still the problem exists.
i removed the -p option,still when i run the script through cron it's creating a directory

/home/namish/backup/backup

this last backup is redundent i just want to remove that part.

Thanks

are you backing up a directory called "backup" as well?

are you backing up a directory called "backup" as well?

No Dima,i am not,every time i run the script it should create a directory backup inside any specific dir and then take backup,when i run cron job the problem is coming,because at the first time it is creating the directories and again at the cron time it is doing the same.

in simple words--
it should take backup always in a directory--

$dir/backup

whether i run it through cron timings or just now.

Thanks.

just use $Backuplocation (without the /backup after it) then

btw, does it work right when run manually, outside of cron?

just use $Backuplocation (without the /backup after it) then

btw, does it work right when run manually, outside of cron?

yes it does work properly when i run it without cron.

it should work like this ---

if i am running it without cron--it checks for the directory existance,if it is there then it creates the dir backup and take the backup of the files,because i am assigning it like this
BackupLocation=$BackupLocation/backup

it runs first time as soon as i run the script,when i run it through cron at a specific time it again creates the dir backup inside BackupLocation(which is now $BackupLocation/backup)

i just want to createit once whether i run it through cron or now.i need to change a bit in the script but notgetting how to do.So your help is required in this.

Thanks

try to use different variables instead of appending /backup to a single location variable

try to use different variables instead of appending /backup to a single location variable

if i use a different variable to store the backuplocation,then when i am running cron the backup is taken in to current directory ie
if backuplocation is /home/namish/backup

when i run the script through cronjob ten it is taking backup at /home/namish not in backup directory.may be some problem in assignment of the variables,that is why i am looking for a help.

Thanks.

#givenPath="$BackupLocation"
BackupLocation1=$BackupLocation/backup
mkdir -p $BackupLocation1 >/dev/null 2>&1

instead of backing up, everywhere you can, echo out the $backuplocation and $backuplocation1 - see what they become during runtime

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.