LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-10-2020, 09:06 AM   #1
limbooface
LQ Newbie
 
Registered: Dec 2020
Posts: 2

Rep: Reputation: Disabled
how to make his one line into a bash shell


Hi this one line works fine in a terminal.

How do I write this find command so that it works in a bash shell script.

find /projects/projectname -type d | parallel -j 32 mmputacl -i /root/folderacltopush.acl {} > /root/folderacltopush.acl.log 2>&1

Thanks
 
Old 12-10-2020, 09:17 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Welcome.

You make a file, change the permissions so that it is executable,

Code:
mkdir ~/bin/
touch ~/bin/myscript
chmod +x ~/bin/myscript
then edit it to contain almost the same information:

Code:
#!/bin/sh

PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin

set -e

find /projects/projectname -type d -print \
| parallel -j 32 mmputacl -i /root/folderacltopush.acl {} \
> /root/folderacltopush.acl.log 2>&1

exit 0
Then you can run it,

Code:
~/bin/myscript
The "set -e" is optional. It causes the script to exit as soon as any command fails. That helps with debugging.

Some resources which are useful for learning shell scripts:

Edit: by the way, the {} does not fit with where it is used and if your formula really does work in the terminal then that part can probably be removed. Perhaps xargs is missing from your script?

Last edited by Turbocapitalist; 12-10-2020 at 09:21 AM.
 
Old 12-10-2020, 10:11 AM   #3
limbooface
LQ Newbie
 
Registered: Dec 2020
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks that worked. If I want to add another find command do i just use the if then statement?
 
Old 12-10-2020, 10:17 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
I didn't see an if-then statement in your example, but that aside the general answer is just keep adding lines to the script as needed.

Notice first that you have a pipe feeding output from find into parallel and then from there you have a redirection to capture that output into a file. So that one line is a three-in-one action.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Man accidentally deletes his entire company' with one line of bad code dugan Linux - News 6 06-17-2016 05:35 AM
Zed Creator Quits His Job, Will Attempt to Make the Open Source Editor His Day Job jeremy Linux - News 0 04-02-2014 12:17 PM
grab the line below a blank line and the line above the next blank line awk or perl? Pantomime Linux - General 7 06-26-2008 08:13 AM
LXer: Linux users tell Ballmer to put his code where his mouth is LXer Syndicated Linux News 0 02-26-2007 09:33 AM
Switch to another user, get his env and run a command 'under his name' ganninu Linux - General 2 05-25-2004 02:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration