1

I am running my below shell script which gets the md5sum of a files in my PRIMARY directory

#!/bin/bash

export PRIMARY=/data01/primary

for entry in "$PRIMARY"/*
do
    local_md5sum=/usr/bin/md5sum "$entry" | awk '{print $1}'
    echo local_md5sum
done

As soon as I run above shell script and try to print out the md5sum value of my files, I always get -

./md5checksum_check_1.sh: line 7: /test01/prime/pp_monthly_1980_58_200003_5.data: Permission denied

But if I try to run the below command as it is on the console then it works fine -

/usr/bin/md5sum /test01/prime/pp_monthly_1980_58_200003_5.data | awk '{print $1}'

I am not sure why? Is there anything wrong I am doing?

  • Are you running your script under cron? If so, then perhaps the user under which it's running does not have permission to read your data file. – Greg Hewgill Sep 22 '14 at 20:10
  • See stackoverflow.com/a/25710660/3776858. – Cyrus Sep 22 '14 at 20:10
  • @GregHewgill No I am not running my script under cron. I am running as the same user which has the file permissions as well. – david Sep 22 '14 at 20:11
  • Ok. Are you running with SELinux enabled? – Greg Hewgill Sep 22 '14 at 20:12
  • I am running Ubuntu 12.04 if that's what you meant? – david Sep 22 '14 at 20:13
3

You're missing some syntax on this line:

local_md5sum=/usr/bin/md5sum "$entry" | awk '{print $1}'

You need

local_md5sum=$(/usr/bin/md5sum "$entry" | awk '{print $1}')

Without the $(), you are trying to execute $entry as a command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.