0

As I am new to bash scripting (vbs is more my stuff), I can't get this to run. Probably very simple for y'all:

I have a bash script on the C-system disk that is starting a NagWin (nagios for windows) plugin, but in that script I want to start off with a line of code that does a file existence checking on the D-drive in a certain folder.

If this file is there, it just can echo a message and exit, else if this is not there it should continue with the script on the C-drive

The other part of the script runs well only it does not do any checking, probably because something is wrong with the jumping to d drive and c drive or something

Already thanks

nobody
  • 59
  • 1
  • 6

3 Answers3

1
if test -f '/path/to/file'; then
  #Do your work
else
  echo 'File not found, exiting.'
fi
Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
0
if [ -f D:/file/on/d/drive ]
then C:/script/on/c/drive
else echo "Did not find file D:/file/on/d/drive" 1>&2
fi
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Thanks ! I forgot my double colon after the drive-path, that is why it was not working. Thanks for helping – nobody Aug 21 '12 at 07:54
0

You can test the presence of a file in different ways in bash:

1)

if [ -f "/path/to/file" ]; then echo "OK"; else echo "KO"; fi

2)

[ -f "/path/to/file" ] && echo "OK"

3)

[ -f "/path/to/file" ] || echo "KO"

4)

if test -f "/path/to/file"; then echo "OK"; else echo "KO"; fi
matteomattei
  • 650
  • 5
  • 9