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

  • Home
  • SEARCH
  • 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 6720775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:15:06+00:00 2026-05-26T09:15:06+00:00

I need to execute a script on a remote server over ssh, I can’t

  • 0

I need to execute a script on a remote server over ssh, I can’t locate the script as a file on the remote server nor create files during the script process.

The script checks for a non existent or zero byte file, and if exists, checks if is outdated.

I’ve followed a thread here on SO and tried this:

myvar=$(ssh user@server <<EOF
myfile=/mnt/file.csv
if [ -s $myfile ]; then
   filedate=$(stat -c %x $myfile|grep '[0-9\-]*' --max-count=1 -o);
   yesterday=$(date --date 'now -1 day' --iso-8601);
   if [ $filedate < $yesterday ]; then
     echo '1 '$yesterday;
   else
     echo '0 ok';
   fi
else
   echo $(date --iso-8601);
fi
EOF
)

sadly, the pipe appears to be truncating the string or something, because the script returns

stat: too few arguments

maybe just cannot use “myfile” var declaration. Any suggestions?

Thanks in advance.

—- Edit: Clarifying answer:

keber-laptop:~ keberflores$ echo $myvar

keber-laptop:~ keberflores$ myvar=$(ssh user@server <<EOF
> myfile=/mnt/file.csv
> if [ -s \$myfile ]; then
>    filedate=\$(stat -c %x \$myfile|grep '[0-9\-]*' --max-count=1 -o);
>    yesterday=\$(date --date 'now -1 day' --iso-8601);
>    if [ \$filedate < \$yesterday ]; then
>      echo '1 '\$yesterday;
>    else
>      echo '0 ok';
>    fi
> else
>    echo '1 '\$(date --iso-8601);
> fi
> EOF
> )
Pseudo-terminal will not be allocated because stdin is not a terminal.
user@server's password: 
keber-laptop:~ keberflores$ echo $?
0
keber-laptop:~ keberflores$ echo $myvar
1 2011-10-22

—- Edit: calling inside perl:

my $myvar = qx'ssh user@server <<\'EOF\'
myfile=/mnt/file.csv
if [ -s $myfile ]; then
   filedate=$(stat -c %x $myfile|grep \'[0-9\-]*\' --max-count=1 -o);
   yesterday=$(date --date \'now -1 day\' --iso-8601);
   if [ $filedate < $yesterday ]; then
     echo \'1 \'$yesterday;
   else
     echo \'0 ok\';
   fi
else
   echo \'1 \'$(date --iso-8601);
fi
EOF
';
print $myvar;
  • 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-26T09:15:07+00:00Added an answer on May 26, 2026 at 9:15 am

    You need more escaping to get this to work. bash is going to evaluate the variables, etc in the here-file locally, then the result of that will be evaluated on the remote server.

    In particular, your $myfile is probably evaluating to an empty string when the here-file is being evaluated, causing the stat to not have a file argument.

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

Sidebar

Related Questions

I need to create a shell script to do this: ssh to another remote
I'm writing a script and I need to create a loop that will execute
I need to execute shell script on my remote linux machine. Do you know
I want to execute a Python script on several (15+) remote machine using SSH.
I need to execute a script in the background through a service. The service
I need to execute a PowerShell script from within C#. The script needs commandline
I am working on a bash script where I need to conditionally execute some
Sometimes (in customer's PCs) I need a python script to execute in the Windows
I'm writing a Inno Setup script which need to execute a very old third
I need to send 500 Internal Server Error from an PHP script under certain

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.