Sponsored Content
Top Forums Shell Programming and Scripting Bash script not parsing file with spaces in path Post 302906647 by gjws on Sunday 22nd of June 2014 02:00:26 PM
Old 06-22-2014
Bash script not parsing file with spaces in path

Hi everyone,

I'm trying to write my first ever shell script, the OS is Raspbian. The code I have written must be executed whenever a certain database has been modified. The database resides on a Windows server to which I have a mount point, and I have no control over the Windows server at all so changing directory names is not an option unfortunately. Here is the script I have written to date:

Code:
#!/bin/sh

DB1="/mnt/qnap/Amarillo/Reckon/Point of Sale Lite 2013 Administrator/QBPOS.TXT"
TF1=/home/pi/scripts/file1

ls --full-time "$DB1"
ls --full-time "$TF1"

if [ "$DB1" -nt "$TF1" ]; then
	echo "Database has been updated since last run"
	echo "Do some stuff here"
	touch /home/pi/scripts/file1
else
	echo "Database has NOT been updated"
fi

Unfortunately, no matter what, the script ALWAYS equates to false. I have included the 'ls' commands in the script purely for debugging purposes so I can check the variable declaration is working correctly and also to verify dates on the files. So when I run the script, this is the output I receive:

Code:
pi@mckinnonPi ~/scripts $ ./fish 
-rwxr-xr-x 1 root root 936 2014-06-22 17:47:15.583175000 +1000 /mnt/qnap/Amarillo/Reckon/Point of Sale Lite 2013 Administrator/QBPOS.TXT
-rw-r--r-- 1 pi pi 0 2014-01-01 12:00:00.000000000 +1100 /home/pi/scripts/file1
Database has NOT been updated

So clearly the declaration for DB1 is working, as the ls command in the script succeeds, and the output also clearly shows that DB1 is indeed the newer of the 2 files, but for some reason the file age test fails. If I change the script to perform the test based on files that do NOT contain spaces in the path then it works as expected, so there is no error in the logic of the code, but clearly the spaces in the pathname are causing a problem.

I've been working on this for a few days now, and I've researched as much as I can but have hit a brick wall. Any help would be very much appreciated.

Thank you!


*** UPDATE ***

I re-wrote the script to point to files on the local server only, taking the CIFS share out of the equation, and IT WORKS! So it would appear that the problem is caused by the fact the database resides on a CIFS share, but why on earth would that be the case when the ls output clearly shows the file is accessible? Here is the mount information just incase it helps to shed some light on the problem:

Code:
//192.168.0.4/backup on /mnt/qnap type cifs (rw,relatime,vers=1.0,sec=ntlmssp,cache=strict,username=guest,domain=WORKGROUP,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.0.4,file_mode=0755,dir_mode=0755,nounix,serverino,rsize=61440,wsize=65536,actimeo=1)


Last edited by gjws; 06-22-2014 at 03:31 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Conversion of bash parsing script to perl?

I need help with a perl parsing script. I have some error logs on a windows machine that I need to parse from a text file, but I know nothing about perl. I usually run this bash script on my linux box and it does just what I need. How would I do the same thing with perl and port it to my windows... (2 Replies)
Discussion started by: cstovall
2 Replies

2. Shell Programming and Scripting

Bash Script to display directories in Path?

Hello there, As a newbie: The directories in PATH can be hard to distinguish when printed out as one line with colon .Please, can i have a sample script to display them,one to a line. Thank you. (1 Reply)
Discussion started by: debut
1 Replies

3. Shell Programming and Scripting

Importing a path/file into a bash script

Hey, I'm new here. Basically, I'm trying to make a bash script that affects a file of my choice. What I want to do is $./script.sh /path/to/file.jpg and then the bash script will know that variable=/path/to/file.jpg Thanks! (4 Replies)
Discussion started by: TFB
4 Replies

4. Shell Programming and Scripting

Help parsing filename with bash script

Hi all! Looking for some help parsing filenames in bash. I have a directory full of files named "livingroom-110111105637.avi". The format is always date and time (yymmddhhmmss). I'm looking to parse the filenames so they are a little more easily readable. Maybe rename them to... (4 Replies)
Discussion started by: mtehonica
4 Replies

5. Shell Programming and Scripting

parsing a config file using bash

Hi , I have a config _file that has 3 columns (Id Name Value ) with many rows . In my bash script i want to be able to parse the file and do a mapping of any Id value so if i have Id of say brand1 then i can use the name (server5X) and Value (CCCC) and so on ... Id Name ... (2 Replies)
Discussion started by: nano2
2 Replies

6. Shell Programming and Scripting

Looking for help with parsing file contents in bash [newbie]

Hi I'm just messing around with bash and trying to learn it because I have a course next semester dealing with OS design where we need to know how to use SSH client and either bash or ksh. I've never done shell scripting before. I just started today and I was wondering how parsing files... (1 Reply)
Discussion started by: mehungry
1 Replies

7. Shell Programming and Scripting

Column parsing in a bash script - HELP

I would like to setup a script that pulls in time/date in two seperate columns, and then name the other columns as listed below: Column1=Art/TJ output Column2=Art/TJ output Column3=TJ output column4=Art output Column5=If time/date past 12:00 noon -fail Colume6=If time/date before... (1 Reply)
Discussion started by: walnutpony123
1 Replies

8. UNIX for Dummies Questions & Answers

Getting path name using bash script

I have this code to extract the directory name ($0:h) in tcsh. I am converting the code to bash and need a way to get the equivalent setting for DefRaytracPath set DefRaytracPath = `echo $0:h | awk 'BEGIN {FS="/tcsh"} {print $1"/prog"}'` (3 Replies)
Discussion started by: kristinu
3 Replies

9. UNIX for Advanced & Expert Users

Parsing a file in bash

Hello All, I have the following input file that i'm trying to parse: 10.0.011.40 hadoop 15526 15524 0 hadoop 15528 15526 0 hadoop 19747 4018 1 10.0.081.227 hadoop 2862 2861 0 hadoop 2864 2862 0 hadoop 12177 14376 1 I'm trying to get this in my output file: 10.0.011.40 15526 15528... (2 Replies)
Discussion started by: ramky79
2 Replies

10. Shell Programming and Scripting

Parsing and Editing a json file with bash script

I am trying to automate editing of a json file using bash script. The file I initially receive is { "appMap": { "URL1": { "name": "a" }, "URL2": { "name": "b" }, "URL3": { "name": "c" }, } WHat I would like to do is replace... (5 Replies)
Discussion started by: Junaid Subhani
5 Replies
UPGRADEDB(8)						      System Manager's Manual						      UPGRADEDB(8)

NAME
upgradedb - Directory Server script for upgrading the database SYNOPSIS
upgradedb [-a archivedir] [-Z serverID] [-f] [-v] [-d debuglevel] [-h] DESCRIPTION
Checks the DB version and if it has the old index formatting then it will rebuild the indexes. This is usually needed after migrating from older versions of Directory Server. This script must be run while the server is stopped. OPTIONS
A summary of options is included below: -n Backend Name The name of the LDBM database to reindex. Example: userRoot -a Database directory The full path to the database directory. -Z Server Identifier The server ID of the Directory Server instance. If there is only one instance on the system, this option can be skipped. -N Only checks whether any DNs in the database need to be updated. -h Display the usage. EXAMPLE
upgradedb -Z instance2 DIAGNOSTICS
Exit status is zero if no errors occur. Errors result in a non-zero exit status and a diagnostic message being written to standard error. AUTHOR
upgradedb was written by the 389 Project. REPORTING BUGS
Report bugs to http://bugzilla.redhat.com. COPYRIGHT
Copyright (C) 2013 Red Hat, Inc. Mar 5, 2013 UPGRADEDB(8)
All times are GMT -4. The time now is 08:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy