Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:30:16+00:00 2026-05-26T15:30:16+00:00

This is my first foray into shell scripting so if i’m asking a very

  • 0

This is my first foray into shell scripting so if i’m asking a very basic question please be gentle with me!

I have a shell script which downloads a file via FTP, uses split to break the file into separate smaller files. I then use a for loop to call a PHP file which does some processing on the file, this PHP process is run in the background to completion.

This 2 script combo works fine when run from the command line under sudo, however when it is run from the cron I don’t seem to be able to get the file name value to pass into PHP.

My 2 test scripts are as follows

shell-test.sh

#!/bin/bash

cd /path/to/directory/containing/split/files/

#Split the file into seperate 80k line files
split -l 80000 /path/to/file/needing/to/be/split/

#Get the current epoch time as all scripts will need to use the same update time
epochtime=$(date +"%s")

echo $epochtime

#Output a list of the files in the directory
ls


#For loop to run through each file in the working directory
#For each file we run the php script with safe mode off (to enable access to includes)
#We pass in the name of the file and epochtime
#The ampersand at the end of the string runs the file in the background in parallel so     that all scripts execute concurrently

for file in *
do
php -d safe_mode=Off /path/to/php/script/shell-test.php -f $file -t $epochtime &
done

#Wait for all scripts to finish
wait

shell-test.php

<?php

$scriptOptions = getopt("f:t:");

print_r($scriptOptions);

?>

When run from the command line outputs the following which is what I need – the file value is passed to the PHP script.

1319824758
xaa  xab  xac  xad
Array
(
[f] => xaa
[t] => 1319824758
)
Array
(
[f] => xac
[t] => 1319824758
)
Array
(
[f] => xad
[t] => 1319824758
)
Array
(
[f] => xab
[t] => 1319824758
)

However when run via the cron the following is outputted

1319825522
xaa
xab
xac
xad
Array
(
[f] => *
[t] => 1319825522
)

So what I need to know is how to get the value of * as the file name and not as the actual string * (and why this is happening would be useful too!).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:30:17+00:00Added an answer on May 26, 2026 at 3:30 pm

    My random guess is that cron is running the shell with the -f option for safety. Try adding

    set +f
    

    to your script. Or find some other way of enumerating the files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My first foray into writing jQuery functions. I have this function, but I'm not
This is my first foray into designing two versions of images for retina or
This is my first foray into using an MVC construct (CodeIgniter). I'm hoping someone
I've worked with CakePHP 1.3, but this is my first foray into CakePHP 2.0
I'm a (near complete) beginner, and this is my first foray into encryption -
This is my first foray into OO JS, having issues. Ideally in this scenario,
Well, this is my first foray into memory profiling a .NET app (CPU tuning
I have a (hopefully) basic question on credit card processing, particularly using Authorize.Net. This
I'm making my first foray into WPF - I have a simple form with
This is my first foray into Java, so forgive me if this is simple,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.