LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-09-2007, 12:51 AM   #1
Sid2007
LQ Newbie
 
Registered: Oct 2007
Posts: 10

Rep: Reputation: 0
What permissions to use to create/delete temp/backup files through a shell script ?


Folks,
I have a shell script that need to create some files:
1) backup files of user passed in file ( that will be written by this shell ).
2) temp files that the shell will create and later delete/remove.

This shell script will be used from my local dir ( I am not a super or a sysadmin ). Users of this shell will call this script to run on their local files in their respective directories.

When my script runs, it errors with the following:
cp: cannot create regular file `./listfile.txt.backup': Permission denied
/home/myUser/tools/myShellScript: line 12: listfile.txt: Permission denied

for the temp I was able to avoid this error by creating the temp file in the /tmp directory.

All I want is for this shell script to run, create/modify/backup files in user's local dirs.

The user dir has the following permission:
drwxr-xr-x testDir

the file that needs to be backed-up has:
-rw-r--r-- listfile.txt.


Any advise gurus?
Any advise will geatly help.

Last edited by Sid2007; 10-09-2007 at 01:57 AM.
 
Old 10-09-2007, 02:10 AM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
A quick script:
Code:
#!/bin/bash
###
### Backup users files using tar
###

##
## Find running user and homedirectory
v_username=`whoami`
v_home_dir=`grep $v_username /etc/passwd|cut -d':' -f6`
v_home_dir=${v_home_dir:-~}

##
## Create backup file in /tmp
tar cvf /tmp/backup_${v_username}.tar ${v_home_dir}

##
## Move the backup file to the users home directory
mv /tmp/backup_${v_username}.tar ${v_home_dir}
There are a few flaws in the idea of backing up a users files to the users home directory, not least of which subsequent backups will backup the previous backup file, therefore the tar will contain the previous tar file.

This will cause the backup to grow exponentially.

Additionally if you lose the home directory, you also lose the backup of it.
 
Old 10-09-2007, 02:28 AM   #3
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
PS the script and the directory it lives in needs to have read and execute permissions for any of the users who will run this script.

If the script is called backup.sh you need to run:

chmod 755 backup.sh

If the directory is /home/testDir, then:

cd /home
chmod 755 testDir


Additionally, why are you (as users) having to backup your own files?
This is normally a part of the Systems Administrators work.
 
Old 10-17-2007, 01:29 PM   #4
Sid2007
LQ Newbie
 
Registered: Oct 2007
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Disillusionist View Post
PS the script and the directory it lives in needs to have read and execute permissions for any of the users who will run this script.

If the script is called backup.sh you need to run:

chmod 755 backup.sh

If the directory is /home/testDir, then:

cd /home
chmod 755 testDir


Additionally, why are you (as users) having to backup your own files?
This is normally a part of the Systems Administrators work.
Great! These are great pointers.
True. This ideally needs to be done by a sys admin. But I was just asked to come up with a script that can fix some string issues that got introduced through another processor.

So, I created the script.
This script creates some temp files.
It also overwrites/updates the 'processed' files to fix errors, typically passed as command line arguments by a user.

What I wanted to be able to do is following:
1. First backup any of the files that need to be fixed.
2. Allow the script to fix the files.
3. Quietly delete/remove the temp files that my script creates.

All this needs to happen in the user's local dir.
 
Old 10-17-2007, 01:55 PM   #5
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
A couple of questions..

How does your script recognise the files that need to be fixed?

How does it know that the fix was successfull? Assume it tests before removing the temporary backup file?

Is this to be run by end users manually or will this be automated via cron?

Is it possible to provide the script that you have so far?

Is it possible to provide a sample broken and fixed file?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to remove backup ~ files hallamigo Linux - General 3 09-13-2010 03:47 PM
Delete temp files. caa1980 Ubuntu 6 03-29-2010 07:47 AM
shell script to compare filese b/w local and remote and delete files from local serve dsids Linux - Networking 9 08-23-2006 07:20 AM
Making shell script to 'locate' m4a files and delete them bd1308 Linux - Software 3 02-12-2006 10:44 AM
How To Delete temp Internet Files? agee220 Linux - Newbie 3 08-25-2004 02:36 PM


All times are GMT -5. The time now is 06:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration