LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-11-2013, 11:08 AM   #16
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled

Quote:
Originally Posted by shivaa View Post
Files and their permissions seem ok. But I don't know from where these command not found errors are coming.

I feel, it would be better if you can post whole script once (if something is confidential, then you can hide that and use dummy entry at that place).
I have set up 10 files in important_files directory and populated with jargon.
I have set up a config script with variables the user should be able to change.
I have a script which checks these variables to see if are present and correct (exist).
The script then should awk the lines from the confile.cfg and populate a backuplist.txt.
From this backup list the script should tar files into tarball and write to errorlog:
tar -czvf $BACKUP_FILE -T "$BACKUP_TARGETS" > "$LOGOUT" 2> "$LOGERR"

For some reason the script is reading the confile.cfg and trying to run each line as a command? - Is this normal, can I subdue this output or redirect it? and How would I do it?

Here seems to be the offending part:

. $CONFILE
+ . /home/ubuntu/confile.cfg
###############################################################
###############################################################
# CONFIGURATION FILE ASSIGNMENT 1 #
# Student: XXXXXXXXXXXXXXX #
###############################################################

# Please enter FULL directory of the files you need backed up after "=" below:
IMPORTANT_FILES_DIRECTORY=$HOME/assignment1/important_files
++ IMPORTANT_FILES_DIRECTORY=/root/assignment1/important_files

# Please enter FULL directory where you want the files be backed up to after "=" below:
BACKUP_FILES_DIRECTORY=$HOME/assignment1/backups
++ BACKUP_FILES_DIRECTORY=/root/assignment1/backups

# Please enter FULL directory where you want the backups to be restored to after "=" below:
RESTORE_FILES_DIRECTORY=$HOME/assignment1/restores
++ RESTORE_FILES_DIRECTORY=/root/assignment1/restores

# Please enter the Project Name to be assigned to the new backup file after "=" below:
PROJECT_NAME=ASSIGNMENT1
++ PROJECT_NAME=ASSIGNMENT1

# Please list the files or directories to be backed up on the next line, hit enter after each line:
/home/ubuntu/assignment1/important_files/file1
++ /home/ubuntu/assignment1/important_files/file1
/home/ubuntu/assignment1/important_files/file1: line 1: kjsdf: command not found
/home/ubuntu/assignment1/important_files/file1: line 2: asdfj: command not found
/home/ubuntu/assignment1/important_files/file1: line 3: asdfjasdf: command not found
/home/ubuntu/assignment1/important_files/file1: line 4: asdf: command not found
/home/ubuntu/assignment1/important_files/file1: line 5: asdf: command not found
/home/ubuntu/assignment1/important_files/file1: line 6: asdf: command not found
/home/ubuntu/assignment1/important_files/file1: line 7: bdrtwertewgrt: command not found
/home/ubuntu/assignment1/important_files/file1: line 8: gsbvwgtr: command not found
/home/ubuntu/assignment1/important_files/file1: line 9: bwetbtrw: command not found
/home/ubuntu/assignment1/important_files/file1: line 10: bwdfre: command not found
/home/ubuntu/assignment1/important_files/file2
++ /home/ubuntu/assignment1/important_files/file2
/home/ubuntu/assignment1/important_files/file2: line 1: rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr: command not found......................AND SO ON....

Last edited by Batistuta_g_2000; 03-11-2013 at 11:20 AM.
 
Old 03-11-2013, 11:26 AM   #17
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
I am sorry, but here we should not share anything privately. In the meantime, you can exclude the reading of this config file, as:

Code:
awk 'NR==20,NR==EOF' "$CONFILE" | grep -v confile.cfg > $TMP/backuplist.txt
 
Old 03-11-2013, 01:19 PM   #18
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
I am sorry, but here we should not share anything privately. In the meantime, you can exclude the reading of this config file, as:

Code:
awk 'NR==20,NR==EOF' "$CONFILE" | grep -v confile.cfg > $TMP/backuplist.txt
Thanks for that. Do you have any idea why the config file at the start of my script is trying to run each file listed from NR==20 to EOF? - is . $CONFILE correct?


So in the top of my script :
Code:
#!/bin/bash
BASEDIR=$(cd `dirname $0` && pwd)
CONFILE=$BASEDIR/confile.cfg
. $CONFILE
root@ubuntu:~# ./assignment1.sh
/home/ubuntu/assignment1/important_files/file1: line 1: kjsdf: command not found
/home/ubuntu/assignment1/important_files/file1: line 2: asdfj: command not found
/home/ubuntu/assignment1/important_files/file1: line 3: asdfjasdf: command not found
/home/ubuntu/assignment1/important_files/file1: line 4: asdf: command not found
/home/ubuntu/assignment1/important_files/file1: line 5: asdf: command not found
/home/ubuntu/assignment1/important_files/file1: line 6: asdf: command not found
 
Old 03-11-2013, 01:32 PM   #19
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Code:
. $CONFILE
Is the problem. A "." means you're sourcing the $CONFILE i.e. reading this file line by line and trying to set everything mentioned in the file.

Simply comment it out. It's not necessory in script.
Code:
#!/bin/bash
BASEDIR=$(cd `dirname $0` && pwd)
CONFILE=$BASEDIR/confile.cfg
#. $CONFILE          # Comment out this line
 
Old 03-11-2013, 01:51 PM   #20
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
Code:
. $CONFILE
Is the problem. A "." means you're sourcing the $CONFILE i.e. reading this file line by line and trying to set everything mentioned in the file.

Simply comment it out. It's not necessory in script.
Code:
#!/bin/bash
BASEDIR=$(cd `dirname $0` && pwd)
CONFILE=$BASEDIR/confile.cfg
#. $CONFILE          # Comment out this line

Ok sorry, a bit of background:
The script has variables set in the confile.cfg which it needs to use.
The confile.cfg must be in the base directory (same location as he script), so is set up as above.
I need to source the confile.cfg in the script so it can be read - is there a better way than. confile.cfg which will not cause the lines to be read from each referenced file?

Thanks

Last edited by Batistuta_g_2000; 03-11-2013 at 01:52 PM.
 
Old 03-11-2013, 02:04 PM   #21
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Better to define those variables in script itself. Else remove those commands from $CONFILE file.
 
Old 03-12-2013, 09:16 AM   #22
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
Better to define those variables in script itself. Else remove those commands from $CONFILE file.
Ok got it sorted:
set my confile to
Enter file names you want to back up after the # below
#file1
#file2....etc

Then in script - awk'd lines to tempfile and sed'd out "#" to tempfile2 and copied to "important_files" directory - Then I ran the script to tar -T from "tempfile2" list within the "important_files" directory" so just got the actual files not full path. BINGO... thanks for the help.
 
  


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
[SOLVED] awk question - read in txt files, offset data by given amount, output new txt files pomico Programming 19 09-17-2012 12:43 PM
How to delete files keeping the files listed in a text file -urgent jeesun Linux - General 4 10-21-2011 12:28 PM
Copy the contents of a txt file to other txt files (with similar names) by cp command TheIndependentAquarius Linux - Newbie 7 07-03-2010 01:54 AM
tar the files listed in other file PMP Linux - Newbie 1 04-21-2009 09:50 AM
tar file listed in the text file nawuza Linux - Newbie 10 07-24-2008 01:22 AM


All times are GMT -5. The time now is 04:16 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration