0

I've Googled a lot but I can't fix this.

For local files I get it to work, but for a networkfile it doesn't.

I want to check if a file on a network exists, but how?

I tried this in my terminal:

 [ -f "192.168.1.46:8090/camera.jpg" ] && echo 1 || echo 0

It outputs constantly 0, while I'm sure the file exists, can anyone help me?

EDIT:

To be more clear:

On my Raspberry Pi (with Raspbian), I run FFserver and FFmpeg. It transcode a stream to camera.mjpeg and camera.jpg. The local IP address of my Raspberry Pi itself is 19.168.1.46, so I want to check if file is still there, because sometimes the transcoding process hangs, and the mjpeg is unreadable. I have this shell code now:

  #!/bin/bash       
  url=http://192.168.1.46:80/test.txt
  url2=http://192.168.1.46:8090/camera.mjpeg

  if curl --output /dev/null --silent --head --fail "$url"; then
    echo "URL exists: $url"
  else
    echo "URL does not exist: $url"
  fi

  if curl --output /dev/null --silent --head --fail "$url2"; then
    echo "URL exists: $url2"
  else
    echo "URL does not exist: $url2"
  fi

This is the output:

  URL exists: http://192.168.1.46:80/test.txt
  URL does not exist: http://192.168.1.46:8090/camera.mjpeg

The problem is: I know for sure the camera.mjpeg is there, because I can access it via a browser on another PC and view it without problems, but it still says that it doesm't exsists.

Lars
  • 11

1 Answers1

-1

192.168.1.46:8090/camera.jpg is just the name of a non-existent file (a file named camera.jpg in a local directory named ./192.168.1.46:8090. Directory ./192.168.1.46:8090 does not exist).

You will need to use a program that can access the server, such as curl or wget.

If the server is HTTP, then use curl option --head to tell the server to not send the file, but only send the HTTP header. This should be enough. e.g. curl --head http://192.168.1.46:8090/camera.jpg