You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.
Join groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
Hello guys,
I am trying to run a .sh script from a post function script using Scriptrunner. What I am currently doing is:
"path/checkurls.sh urls.txt".execute()
Nothing seems to happen. The sh script I am trying to run is:
#!/bin/bash
while read url
do
some stuff
echo "$url $urlstatus" >> urlstatus.txt
done < $1
Do you know what might be going wrong?
Here is how I execute OS-level commands:
def sout = new StringBuilder()
def serr = new StringBuilder()
def cmd = "some command linke"
def proc = cmd.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(60000)
if(serr){
log.error("Error executing command: $cmd \n$serr")
} else {
log.info("Command [$cmd] executed sucessfully with following output:\n$sout")
}
Now, tail your atlassian-jira.log file and see what happens, you should get some clues as to why your command didn't execute.
One thing to try ... in your command rather than rely on the sh-bang directive, try
"bash /path/checkurls.sh".execute()
Thank you, @Peter-Dave Sheehan ! after some adaptations, the code you provided was very good basis to start from!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mihai_Perdum ,
This is the snippet I use to exec sh files :
def command = "path/checkurls.sh urls.txt"
int returnCode = Runtime.getRuntime().exec(command);
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Antoine Berry ,
Thanks for the quick answer. I just tried it but it doesn't work. I switched the bash script to something even simpler
#!/bin/bash
valid=true
count=1
while [ $valid ]
do
echo $count
if [ $count -eq 5 ];
then
break
fi
((count++))
done
so what I tried doing with the snippet you provided was :
def command = "path/checkurls.sh > output.txt"
Runtime.getRuntime().exec(command);
I had to remove the int variable you defined because it was throwing a cast error.
Any other recommendations?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
At this point your best bet would be to check the logs. Maybe there is a system discrepancy that explains why it is not working. Also make sure your sh script is working first.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you but all I am seeing in the logs is:
1 error
2019-07-26 11:47:24,067 http-nio-8080-exec-14 ERROR zerobarat1 707x292x1 10o9jx6 0:0:0:0:0:0:0:1 /secure/QuickCreateIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] actionId is 1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You would probably need to debug a bit further :
def command = "path/checkurls.sh > output.txt"
def return = Runtime.getRuntime().exec(command);
log.error("command executed !")
def returnCode = return.waitFor()
log.error("with return code : " + returnCode)
In the case the command is executed you might want to add some echo in the sh file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This morning, Atlassian announced the acquisition of ThinkTilt , the maker of ProForma, a no-code/low code form builder with 700+ customers worldwide. ThinkTilt helps IT empower any team in their or...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.