Command not executing inside shell script?two crons not running simultaniously?init.d script not...

Deletion of copy-ctor & copy-assignment - public, private or protected?

Wrapping homogeneous Python objects

Synchronized implementation of a bank account in Java

How to get the n-th line after a grepped one?

Fewest number of steps to reach 200 using special calculator

Optimising a list searching algorithm

When to use snap-off blade knife and when to use trapezoid blade knife?

Print a physical multiplication table

Relation between independence and correlation of uniform random variables

Hausdorff dimension of the boundary of fibres of Lipschitz maps

What does "Four-F." mean?

Light propagating through a sound wave

Does multi-classing into Fighter give you heavy armor proficiency?

Is a party consisting of only a bard, a cleric, and a warlock functional long-term?

Four married couples attend a party. Each person shakes hands with every other person, except their own spouse, exactly once. How many handshakes?

Should I use acronyms in dialogues before telling the readers what it stands for in fiction?

I got the following comment from a reputed math journal. What does it mean?

Have the tides ever turned twice on any open problem?

Why is indicated airspeed rather than ground speed used during the takeoff roll?

How could an airship be repaired midflight?

Do I need to be arrogant to get ahead?

Do US professors/group leaders only get a salary, but no group budget?

What (if any) is the reason to buy in small local stores?

Existence of a celestial body big enough for early civilization to be thought of as a second moon



Command not executing inside shell script?


two crons not running simultaniously?init.d script not executing?executing a shell-script through makefileBad interpreter error when executing shell script with the correct shebang lineCannot start a scriptHow to kill screen session with running sudo command?Executing Perl command from shell script not resulting into anythingSpaced string variable as command parameter inside shell scriptScript Shell Extract substringImporting variables in one shell script from another without executing the referred shell scriptcp command not executing after running other script inside bash script .













0















#!/bin/bash
value=$(</var/www/sym_monitor/man.txt)


if [ "$value" == "true" ]; then

ps -ef|grep sym |grep -v grep |awk '{ print $2 }'|sudo xargs kill -9;


(cd /var/www/symmetric-ds-3.1.6/bin;sudo ./sym --port 8082 --server);

fi


The second command inside brackets is not executing any idea why this is happening?










share|improve this question
















bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • What is the name of the script?

    – choroba
    Feb 18 '13 at 11:46











  • restart.sh is the name of the script.

    – user1597811
    Feb 18 '13 at 11:54











  • Are you getting any error messages? How do you execute the script?

    – Dennis
    Feb 18 '13 at 12:20






  • 1





    Then why do you use sudo?

    – Dennis
    Feb 18 '13 at 14:48






  • 1





    Why? Without additional parameters, sudo is used to execute a command as the root user. Inside a script executed from root's crontab, sudo can't have that effect.

    – Dennis
    Feb 25 '13 at 12:48
















0















#!/bin/bash
value=$(</var/www/sym_monitor/man.txt)


if [ "$value" == "true" ]; then

ps -ef|grep sym |grep -v grep |awk '{ print $2 }'|sudo xargs kill -9;


(cd /var/www/symmetric-ds-3.1.6/bin;sudo ./sym --port 8082 --server);

fi


The second command inside brackets is not executing any idea why this is happening?










share|improve this question
















bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • What is the name of the script?

    – choroba
    Feb 18 '13 at 11:46











  • restart.sh is the name of the script.

    – user1597811
    Feb 18 '13 at 11:54











  • Are you getting any error messages? How do you execute the script?

    – Dennis
    Feb 18 '13 at 12:20






  • 1





    Then why do you use sudo?

    – Dennis
    Feb 18 '13 at 14:48






  • 1





    Why? Without additional parameters, sudo is used to execute a command as the root user. Inside a script executed from root's crontab, sudo can't have that effect.

    – Dennis
    Feb 25 '13 at 12:48














0












0








0








#!/bin/bash
value=$(</var/www/sym_monitor/man.txt)


if [ "$value" == "true" ]; then

ps -ef|grep sym |grep -v grep |awk '{ print $2 }'|sudo xargs kill -9;


(cd /var/www/symmetric-ds-3.1.6/bin;sudo ./sym --port 8082 --server);

fi


The second command inside brackets is not executing any idea why this is happening?










share|improve this question
















#!/bin/bash
value=$(</var/www/sym_monitor/man.txt)


if [ "$value" == "true" ]; then

ps -ef|grep sym |grep -v grep |awk '{ print $2 }'|sudo xargs kill -9;


(cd /var/www/symmetric-ds-3.1.6/bin;sudo ./sym --port 8082 --server);

fi


The second command inside brackets is not executing any idea why this is happening?







linux ubuntu shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 25 '13 at 12:28







user1597811

















asked Feb 18 '13 at 11:43









user1597811user1597811

1055




1055





bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 9 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • What is the name of the script?

    – choroba
    Feb 18 '13 at 11:46











  • restart.sh is the name of the script.

    – user1597811
    Feb 18 '13 at 11:54











  • Are you getting any error messages? How do you execute the script?

    – Dennis
    Feb 18 '13 at 12:20






  • 1





    Then why do you use sudo?

    – Dennis
    Feb 18 '13 at 14:48






  • 1





    Why? Without additional parameters, sudo is used to execute a command as the root user. Inside a script executed from root's crontab, sudo can't have that effect.

    – Dennis
    Feb 25 '13 at 12:48



















  • What is the name of the script?

    – choroba
    Feb 18 '13 at 11:46











  • restart.sh is the name of the script.

    – user1597811
    Feb 18 '13 at 11:54











  • Are you getting any error messages? How do you execute the script?

    – Dennis
    Feb 18 '13 at 12:20






  • 1





    Then why do you use sudo?

    – Dennis
    Feb 18 '13 at 14:48






  • 1





    Why? Without additional parameters, sudo is used to execute a command as the root user. Inside a script executed from root's crontab, sudo can't have that effect.

    – Dennis
    Feb 25 '13 at 12:48

















What is the name of the script?

– choroba
Feb 18 '13 at 11:46





What is the name of the script?

– choroba
Feb 18 '13 at 11:46













restart.sh is the name of the script.

– user1597811
Feb 18 '13 at 11:54





restart.sh is the name of the script.

– user1597811
Feb 18 '13 at 11:54













Are you getting any error messages? How do you execute the script?

– Dennis
Feb 18 '13 at 12:20





Are you getting any error messages? How do you execute the script?

– Dennis
Feb 18 '13 at 12:20




1




1





Then why do you use sudo?

– Dennis
Feb 18 '13 at 14:48





Then why do you use sudo?

– Dennis
Feb 18 '13 at 14:48




1




1





Why? Without additional parameters, sudo is used to execute a command as the root user. Inside a script executed from root's crontab, sudo can't have that effect.

– Dennis
Feb 25 '13 at 12:48





Why? Without additional parameters, sudo is used to execute a command as the root user. Inside a script executed from root's crontab, sudo can't have that effect.

– Dennis
Feb 25 '13 at 12:48










1 Answer
1






active

oldest

votes


















0














You must use an absolute path with sudo, for security reasons:



( sudo /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server );


Check the output of sudo -l to confirm. From the sudoers man page (1.7.x):




A Cmnd_List is a list of one or more commandnames, directories, and
other aliases. A commandname is a fully qualified filename which may
include shell-style wildcards (see the Wildcards section below).




sudo xargs works because xargs is (almost certainly) found in a trusted path (/usr/bin).



Also, check out pgrep and pkill, it will save you the needless ps pipe acrobatics.



You have the potential for resource leaks and other unwanted behaviour with an unconditional kill -9, see https://unix.stackexchange.com/questions/8916/why-not-kill-9-a-process .



Update you've added that you run this via root's crontab -- root has no need to use sudo, and in some cases root may be prevented from running sudo, check what sudo -l says when you are root. If you want to to be able to start a program (that doesn't switch its own uid) as a specific userid then the common way is su - username -c "command" .






share|improve this answer


























  • Im trying these things. I will let you know after my cron got executed.

    – user1597811
    Feb 18 '13 at 12:19











  • No it is not preventing the root from running sudo bcoz the first command also got sudo in it and it is working absolutely fine. Any more suggestions?

    – user1597811
    Feb 25 '13 at 6:32











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f553728%2fcommand-not-executing-inside-shell-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You must use an absolute path with sudo, for security reasons:



( sudo /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server );


Check the output of sudo -l to confirm. From the sudoers man page (1.7.x):




A Cmnd_List is a list of one or more commandnames, directories, and
other aliases. A commandname is a fully qualified filename which may
include shell-style wildcards (see the Wildcards section below).




sudo xargs works because xargs is (almost certainly) found in a trusted path (/usr/bin).



Also, check out pgrep and pkill, it will save you the needless ps pipe acrobatics.



You have the potential for resource leaks and other unwanted behaviour with an unconditional kill -9, see https://unix.stackexchange.com/questions/8916/why-not-kill-9-a-process .



Update you've added that you run this via root's crontab -- root has no need to use sudo, and in some cases root may be prevented from running sudo, check what sudo -l says when you are root. If you want to to be able to start a program (that doesn't switch its own uid) as a specific userid then the common way is su - username -c "command" .






share|improve this answer


























  • Im trying these things. I will let you know after my cron got executed.

    – user1597811
    Feb 18 '13 at 12:19











  • No it is not preventing the root from running sudo bcoz the first command also got sudo in it and it is working absolutely fine. Any more suggestions?

    – user1597811
    Feb 25 '13 at 6:32
















0














You must use an absolute path with sudo, for security reasons:



( sudo /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server );


Check the output of sudo -l to confirm. From the sudoers man page (1.7.x):




A Cmnd_List is a list of one or more commandnames, directories, and
other aliases. A commandname is a fully qualified filename which may
include shell-style wildcards (see the Wildcards section below).




sudo xargs works because xargs is (almost certainly) found in a trusted path (/usr/bin).



Also, check out pgrep and pkill, it will save you the needless ps pipe acrobatics.



You have the potential for resource leaks and other unwanted behaviour with an unconditional kill -9, see https://unix.stackexchange.com/questions/8916/why-not-kill-9-a-process .



Update you've added that you run this via root's crontab -- root has no need to use sudo, and in some cases root may be prevented from running sudo, check what sudo -l says when you are root. If you want to to be able to start a program (that doesn't switch its own uid) as a specific userid then the common way is su - username -c "command" .






share|improve this answer


























  • Im trying these things. I will let you know after my cron got executed.

    – user1597811
    Feb 18 '13 at 12:19











  • No it is not preventing the root from running sudo bcoz the first command also got sudo in it and it is working absolutely fine. Any more suggestions?

    – user1597811
    Feb 25 '13 at 6:32














0












0








0







You must use an absolute path with sudo, for security reasons:



( sudo /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server );


Check the output of sudo -l to confirm. From the sudoers man page (1.7.x):




A Cmnd_List is a list of one or more commandnames, directories, and
other aliases. A commandname is a fully qualified filename which may
include shell-style wildcards (see the Wildcards section below).




sudo xargs works because xargs is (almost certainly) found in a trusted path (/usr/bin).



Also, check out pgrep and pkill, it will save you the needless ps pipe acrobatics.



You have the potential for resource leaks and other unwanted behaviour with an unconditional kill -9, see https://unix.stackexchange.com/questions/8916/why-not-kill-9-a-process .



Update you've added that you run this via root's crontab -- root has no need to use sudo, and in some cases root may be prevented from running sudo, check what sudo -l says when you are root. If you want to to be able to start a program (that doesn't switch its own uid) as a specific userid then the common way is su - username -c "command" .






share|improve this answer















You must use an absolute path with sudo, for security reasons:



( sudo /var/www/symmetric-ds-3.1.6/bin/sym --port 8082 --server );


Check the output of sudo -l to confirm. From the sudoers man page (1.7.x):




A Cmnd_List is a list of one or more commandnames, directories, and
other aliases. A commandname is a fully qualified filename which may
include shell-style wildcards (see the Wildcards section below).




sudo xargs works because xargs is (almost certainly) found in a trusted path (/usr/bin).



Also, check out pgrep and pkill, it will save you the needless ps pipe acrobatics.



You have the potential for resource leaks and other unwanted behaviour with an unconditional kill -9, see https://unix.stackexchange.com/questions/8916/why-not-kill-9-a-process .



Update you've added that you run this via root's crontab -- root has no need to use sudo, and in some cases root may be prevented from running sudo, check what sudo -l says when you are root. If you want to to be able to start a program (that doesn't switch its own uid) as a specific userid then the common way is su - username -c "command" .







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 13 '17 at 12:37









Community

1




1










answered Feb 18 '13 at 11:58









mr.spuraticmr.spuratic

2,0731313




2,0731313













  • Im trying these things. I will let you know after my cron got executed.

    – user1597811
    Feb 18 '13 at 12:19











  • No it is not preventing the root from running sudo bcoz the first command also got sudo in it and it is working absolutely fine. Any more suggestions?

    – user1597811
    Feb 25 '13 at 6:32



















  • Im trying these things. I will let you know after my cron got executed.

    – user1597811
    Feb 18 '13 at 12:19











  • No it is not preventing the root from running sudo bcoz the first command also got sudo in it and it is working absolutely fine. Any more suggestions?

    – user1597811
    Feb 25 '13 at 6:32

















Im trying these things. I will let you know after my cron got executed.

– user1597811
Feb 18 '13 at 12:19





Im trying these things. I will let you know after my cron got executed.

– user1597811
Feb 18 '13 at 12:19













No it is not preventing the root from running sudo bcoz the first command also got sudo in it and it is working absolutely fine. Any more suggestions?

– user1597811
Feb 25 '13 at 6:32





No it is not preventing the root from running sudo bcoz the first command also got sudo in it and it is working absolutely fine. Any more suggestions?

– user1597811
Feb 25 '13 at 6:32


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f553728%2fcommand-not-executing-inside-shell-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

Tribunal Administrativo e Fiscal de Mirandela Referências Menu de...

looking for continuous Screen Capture for retroactivly reproducing errors, timeback machineRolling desktop...