remote/automated OS X folder label indexes triggered from PHP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remote/automated OS X folder label indexes triggered from PHP
# 1  
Old 06-05-2012
remote/automated OS X folder label indexes triggered from PHP

I have a shell script that updates OS X color label indexes of folders/files as specified in an XML file. This works from terminal, but not when I trigger it from Apache/PHP. The server is not public, so not too worried about security. I've tried to allow access in sudoers, but no dice. I could use a cron script to make the update, but was really hoping to not need to do that. Any ideas?

line in sudoers:

Code:
www-data ALL=NOPASSWD: /Library/WebServer/Documents/osx_labels/update_labels.sh

Example XML:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <entry>
        <name>/Library/WebServer/Documents/osx_labels/ATT-00242 - 1108_1112 Tutorial Videos</name>
        <color>Green</color>
    </entry>
    <entry>
        <name>/Library/WebServer/Documents/osx_labels/ATT-00259 - Differentiated Pricing Mock-ups</name>
        <color>Blue</color>
    </entry>
</root>

update_labels.sh:

Code:
#!/bin/bash
count=1
input=/Library/WebServer/Documents/osx_labels/folders.xml
#input=http://staging.seven2.net/test/folders.xml

while [ -n "$name" -o $count = 1 ]
do
    #iterate XML with xpath to retrieve values and set folder label indexes
    name=`cat $input | xpath //entry[$count]/name 2>/dev/null | sed s/\<name\>//g| sed s/\<\\\\/name\>//g`
    color=`cat $input | xpath //entry[$count]/color 2>/dev/null | sed s/\<color\>//g| sed s/\<\\\\/color\>//g`
    if [ "$name" -a "$color" ]; then
		#setlabel from osxutils by Sveinbjorn Thordarson
		setlabel "$color" "$name" 
    fi
    count=$((count+1))
done

update_labels.php:

Code:
<?php
	$output = shell_exec("sh update_labels.sh");
	echo $output;
?>

---------- Post updated at 04:56 PM ---------- Previous update was at 03:11 PM ----------

I didn't mention that I'm incredibly new at this stuff. I didn't think there were errors, and now I see:

update_labels.sh: line 14: setlabel: command not found
update_labels.sh: line 14: setlabel: command not found

So looks like osxutils commands are recognized only when run from terminal???
# 2  
Old 06-05-2012
Every process inherits its environment from its calling process. If you log in to a system, a certain environment is set (by ".profile", ".bashrc"/".kshrc", etc.) and if you call a script from within this environment - like from the command line - it will inherit this evironment.

Chances are, that Apache runs from a different user with a greatly reduced environment and therefore your script doesn't work any more - probably fro lacking vital environment variables like "PATH", etc..

You will have to set a valid environmet inside your script yourself.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do you compare two folders and copy the difference to a third folder in a remote server?

How do you compare one local folder and a remote folder and copy the difference to a third folder in a remote folder.e.g. Folder A -- Is in a remote server and it has the following files TEST1.OUT TEST2.OUT TEST3.OUT Folder B --Is in a local server and it has the following files ... (5 Replies)
Discussion started by: cumeh1624
5 Replies

2. Shell Programming and Scripting

Check if remote folder exists

Hi, When trying to chk if a folder exists on remote server using the below command (got it from other thread in this forum) "ifvchr@s1.mrix.local '/cygdrive/d/shares/projects\ data\ load/test\ files/$SCPED_FILES$name$code'`]; then echo "Directory exists"; else echo "Directory... (0 Replies)
Discussion started by: funonnet
0 Replies

3. OS X (Apple)

Automated command ; extracting files from folders and copying them into a single folder

Hello everyone, I'm running Mac OS X Leopard (10.5.8) and I want to use the Terminal to help automate this tedious and laborious command for me: I need to extract all of the .m4p files in my "iTunes Music" folder which reside in folders of the artist, and then subfolders for the albums and... (2 Replies)
Discussion started by: qcom
2 Replies

4. UNIX for Advanced & Expert Users

How to copy folder from one server to remote one using SSH

ok guys. I have a Centos server running a large website I own. Its is severely struggling under the load and I am having to move to a new load balanced setup. The servers are both remote (to me) and although I can do most things admin wise in nix, I am struggling a bit to come up with a way... (1 Reply)
Discussion started by: anderow
1 Replies

5. Shell Programming and Scripting

Unzip folder on remote machine

Hi ! I am trying to automate FTP transfer of some folders from one unix machine (a) to another one (b). I run my shell script on machine a. The problem I face is how to unzip the folder at the machine b with script run in machine a. My first question: Is there any way to do this ? My... (10 Replies)
Discussion started by: siba
10 Replies

6. Shell Programming and Scripting

matrix indexes

I wanted to use matrixs in awk and got some problem, here is some of the script code, from the BEGIN tag: row_char="a";row_char="b";row_char="c";row_char="d";row_char="e"$ row_char="h";row_char="i";row_char="j";row_char="k"; from the proccess passage: sentence,1]=1; diffrence=4; i=7;... (2 Replies)
Discussion started by: tal
2 Replies

7. Shell Programming and Scripting

moving a file to a new folder and automated ftp

how to move a file to a different folder after an automated FTP . (1 Reply)
Discussion started by: dineshr85
1 Replies

8. UNIX for Dummies Questions & Answers

remote folder

hi i want to create a folder that connects to another server. I am going to be running a program that is cpu intensive on server #1, but that same server, server #1, does not have alot of space and therefore can not store the files even temporarly. I want to create a directory on server #1 that... (1 Reply)
Discussion started by: azezal
1 Replies

9. UNIX for Dummies Questions & Answers

using sed with indexes

Hi people, Is this possible and if so any tips are very welcome. Im trying to do the following: this is what I have: 800__1__ this is what I want: 8000010 12345678 Im... (1 Reply)
Discussion started by: seaten
1 Replies

10. Shell Programming and Scripting

Check Remote Folder Exists

Hi, I want to sftp some files to a remote directory. Before transferring files i want to check whether the required folder exists. If so copy the files to that folder, else create the folder and copy the files. Thanks in adv (1 Reply)
Discussion started by: borncrazy
1 Replies
Login or Register to Ask a Question