Hack Forums
Bash Scripting - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88)
+---- Forum: Linux (https://hackforums.net/forumdisplay.php?fid=85)
+---- Thread: Bash Scripting (/showthread.php?tid=4137170)



Bash Scripting - Sʜᴀᴅᴏᴡ Rᴇᴀʟᴍ - Mar 26, 2014

So at our work we have (I know this should be in the Mac section but they are mostly retards spurting mac is great, mac is god)

2 Macs
1 Windows XP Computer
1 Mac Server

And we have a permissions error on the server which makes it so one mac can't read anothers file and it's being a bitch that I'm not in the mood for fixing and I'm also to busy to do so and I've just got a simple bash script at the moment like this

Code
#!/bin/bash
cd '/Shared Items'
chmod -R 775 Photos
echo "Photos Successfully done"

Is that right or is there a better way to do it?

And then to run that every minute or so, just add it to a cronjob? Or would it be easier to make another script on my bosses computer so that whenever the permissions play up she can just click that and it would fix everything (It would have to login over SSH though)


* - Trip2nite - Mar 27, 2014

You could consider moving them into a group and give that group permissions.
Else it is looking fine.

You could also try chmod 775 /$FOLDER/*
It should change all permissions inside folder to 775.

I wont recommend adding it to cronjob to run every minute or so.


* - vaggie_talez - Mar 27, 2014

Just keep in mind, whether it successfully works or not, it's going to print the success message. It has no kind of error control (which for your implementation is probably fine, this is changing file permissions, not rocket science, lol)

If you do decide to run it as a cron, you should probably use absolute paths instead of relative (including the commands), since I've had a number of scripts run fine when executed by a user, but break when trying it as a cron job. Adding the ab paths fixed it. Also, I agree with the sentiment that a cron job ever couple minutes for something like this probably isn't a great idea.


* - Loki123 - Mar 27, 2014

chmod 775 /$FOLDER/*
means that just the permissions on files and directories inside $FOLDER get changed. Thus $FOLDER/file but not $FOLDER/folder/file ...

@OP
your script looks fine. There are probably better ways to do this but it will work adding it to cron.
/path/to/script

Yes,
is allowed thus it being run all the time.

Cron explanation if you don't know how.

# * command to execute
# ┬ ┬ ┬ ┬ ┬
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ └───── day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
# │ │ │ └────────── month (1 - 12)
# │ │ └─────────────── day of month (1 - 31)
# │ └──────────────────── hour (0 - 23)
# └───────────────────────── min (0 - 59)


* - Trip2nite - Mar 27, 2014

My mistake, forgot the option.

He would need to put -R behind chmod.

so the command would look like this:
Code
chmod -R /$folder

-R =
Quote:-R, --recursive
change files and directories recursively




* - Loki123 - Mar 27, 2014

(Mar 27, 2014 10:52 AM)vmN Wrote:  My mistake, forgot the option.

He would need to put -R behind chmod.

so the command would look like this:
Code
chmod -R /$folder

-R =

The -R flag was there aldready 🤫


* - Trip2nite - Mar 27, 2014

How the...
I guess I'm to tired, so I better go to bed.

Code
sleep 12h