Add entry for a logfile

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















How can I add a logfile line to the following bash file?



#!/bin/sh

if ps x |grep -v grep |grep -c cccam_2.3.2 >/dev/null
then
echo "cccam... ok"
else
echo "cccam... restarting"
/var/bin/cccam_2.3.2 &
fi









share|improve this question
























  • What do you mean by add a logfile line? Do you want to send the echo stuff to your logfile instead to stdout?

    – Thomas
    Jan 27 at 14:00











  • I mean:see a log file e.g in tmp or else only" if the program has been restarted"

    – ddinc
    Jan 27 at 14:19











  • Sorry, still did not get what you actually want to achieve. Do you just want to create an empty file in /tmp? Or do you want to put some information there?

    – Thomas
    Jan 27 at 14:40















0















How can I add a logfile line to the following bash file?



#!/bin/sh

if ps x |grep -v grep |grep -c cccam_2.3.2 >/dev/null
then
echo "cccam... ok"
else
echo "cccam... restarting"
/var/bin/cccam_2.3.2 &
fi









share|improve this question
























  • What do you mean by add a logfile line? Do you want to send the echo stuff to your logfile instead to stdout?

    – Thomas
    Jan 27 at 14:00











  • I mean:see a log file e.g in tmp or else only" if the program has been restarted"

    – ddinc
    Jan 27 at 14:19











  • Sorry, still did not get what you actually want to achieve. Do you just want to create an empty file in /tmp? Or do you want to put some information there?

    – Thomas
    Jan 27 at 14:40













0












0








0








How can I add a logfile line to the following bash file?



#!/bin/sh

if ps x |grep -v grep |grep -c cccam_2.3.2 >/dev/null
then
echo "cccam... ok"
else
echo "cccam... restarting"
/var/bin/cccam_2.3.2 &
fi









share|improve this question
















How can I add a logfile line to the following bash file?



#!/bin/sh

if ps x |grep -v grep |grep -c cccam_2.3.2 >/dev/null
then
echo "cccam... ok"
else
echo "cccam... restarting"
/var/bin/cccam_2.3.2 &
fi






scripting logs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 27 at 15:19









Jeff Schaller

41.5k1056131




41.5k1056131










asked Jan 27 at 13:48









ddincddinc

1




1












  • What do you mean by add a logfile line? Do you want to send the echo stuff to your logfile instead to stdout?

    – Thomas
    Jan 27 at 14:00











  • I mean:see a log file e.g in tmp or else only" if the program has been restarted"

    – ddinc
    Jan 27 at 14:19











  • Sorry, still did not get what you actually want to achieve. Do you just want to create an empty file in /tmp? Or do you want to put some information there?

    – Thomas
    Jan 27 at 14:40

















  • What do you mean by add a logfile line? Do you want to send the echo stuff to your logfile instead to stdout?

    – Thomas
    Jan 27 at 14:00











  • I mean:see a log file e.g in tmp or else only" if the program has been restarted"

    – ddinc
    Jan 27 at 14:19











  • Sorry, still did not get what you actually want to achieve. Do you just want to create an empty file in /tmp? Or do you want to put some information there?

    – Thomas
    Jan 27 at 14:40
















What do you mean by add a logfile line? Do you want to send the echo stuff to your logfile instead to stdout?

– Thomas
Jan 27 at 14:00





What do you mean by add a logfile line? Do you want to send the echo stuff to your logfile instead to stdout?

– Thomas
Jan 27 at 14:00













I mean:see a log file e.g in tmp or else only" if the program has been restarted"

– ddinc
Jan 27 at 14:19





I mean:see a log file e.g in tmp or else only" if the program has been restarted"

– ddinc
Jan 27 at 14:19













Sorry, still did not get what you actually want to achieve. Do you just want to create an empty file in /tmp? Or do you want to put some information there?

– Thomas
Jan 27 at 14:40





Sorry, still did not get what you actually want to achieve. Do you just want to create an empty file in /tmp? Or do you want to put some information there?

– Thomas
Jan 27 at 14:40










2 Answers
2






active

oldest

votes


















2














I believe you want to use logger command like here:



root@dst:~# logger "Hello log stuff."
root@dst:~# grep Hello /var/log/messages
Jan 27 16:32:42 dst root: Hello log stuff.


man logger provides nice options too.






share|improve this answer























  • @Thomas.Should be a file in tmp with only the date and time when the process was restarted

    – ddinc
    Jan 27 at 17:05











  • @ddinc logger uses the standard logging facility - an excellent suggestion given you only said you wanted a log line, and didn't specify it had to be a suboptimal home-grown solution.

    – roaima
    Jan 27 at 17:08












  • sorry for causing misunderstanding.but I still don't know how to put a logger command everytime ""echo "cccam... restarting""" occurs.

    – ddinc
    Jan 28 at 9:08











  • add line: logger "cccam... restarting"

    – Radek Radek
    Jan 28 at 10:04


















0














I think you can also add -x with shell script and redirect that to a logfile. I use it to log and debug few shell scripts



Something like this



sh -x your_script.sh 2> logfile.log





share|improve this answer























  • Thanks for the replies

    – ddinc
    Jan 28 at 18:07











  • don't know if I got it right but both suggestions produce no logs #!/bin/sh if ps x |grep -v grep |grep -c cccam_2.3.2 >/dev/null then echo "cccam... ok" else echo "cccam... restarting" /var/bin/cccam_2.3.2 & sh -x cccam.sh 2> logfile.log fi

    – ddinc
    Jan 29 at 9:29











  • @ddinc what do you see if you run the sh -x your_script.sh 2> logfile.log outside the script. This should create a log of the shell script while its running into the logfile you mention in the same location.

    – Atul
    Jan 29 at 15:19












  • get this:root@dm820:/var/bin# sh -x cccam.sh 2> logfile.log cccam... ok root@dm820:/var/bin# cccam.sh cccam... ok root@dm820:/var/bin# no log though

    – ddinc
    Jan 30 at 8:20











  • [root@localhost ~]# sh -x shell.sh 2> log cccam... restarting [root@localhost ~]# cat log + grep -v grep + ps x + grep -c cccam_2.3.2 + echo 'cccam... restarting' + /var/bin/cccam_2.3.2 shell.sh: line 8: /var/bin/cccam_2.3.2: No such file or directory I did a small test on one my VM using your code and see a log like this. I didnt had the right files so i got error. Is this close to what you need ?

    – Atul
    Jan 30 at 10:50











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f497017%2fadd-entry-for-a-logfile%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














I believe you want to use logger command like here:



root@dst:~# logger "Hello log stuff."
root@dst:~# grep Hello /var/log/messages
Jan 27 16:32:42 dst root: Hello log stuff.


man logger provides nice options too.






share|improve this answer























  • @Thomas.Should be a file in tmp with only the date and time when the process was restarted

    – ddinc
    Jan 27 at 17:05











  • @ddinc logger uses the standard logging facility - an excellent suggestion given you only said you wanted a log line, and didn't specify it had to be a suboptimal home-grown solution.

    – roaima
    Jan 27 at 17:08












  • sorry for causing misunderstanding.but I still don't know how to put a logger command everytime ""echo "cccam... restarting""" occurs.

    – ddinc
    Jan 28 at 9:08











  • add line: logger "cccam... restarting"

    – Radek Radek
    Jan 28 at 10:04















2














I believe you want to use logger command like here:



root@dst:~# logger "Hello log stuff."
root@dst:~# grep Hello /var/log/messages
Jan 27 16:32:42 dst root: Hello log stuff.


man logger provides nice options too.






share|improve this answer























  • @Thomas.Should be a file in tmp with only the date and time when the process was restarted

    – ddinc
    Jan 27 at 17:05











  • @ddinc logger uses the standard logging facility - an excellent suggestion given you only said you wanted a log line, and didn't specify it had to be a suboptimal home-grown solution.

    – roaima
    Jan 27 at 17:08












  • sorry for causing misunderstanding.but I still don't know how to put a logger command everytime ""echo "cccam... restarting""" occurs.

    – ddinc
    Jan 28 at 9:08











  • add line: logger "cccam... restarting"

    – Radek Radek
    Jan 28 at 10:04













2












2








2







I believe you want to use logger command like here:



root@dst:~# logger "Hello log stuff."
root@dst:~# grep Hello /var/log/messages
Jan 27 16:32:42 dst root: Hello log stuff.


man logger provides nice options too.






share|improve this answer













I believe you want to use logger command like here:



root@dst:~# logger "Hello log stuff."
root@dst:~# grep Hello /var/log/messages
Jan 27 16:32:42 dst root: Hello log stuff.


man logger provides nice options too.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 27 at 15:37









Radek RadekRadek Radek

514




514












  • @Thomas.Should be a file in tmp with only the date and time when the process was restarted

    – ddinc
    Jan 27 at 17:05











  • @ddinc logger uses the standard logging facility - an excellent suggestion given you only said you wanted a log line, and didn't specify it had to be a suboptimal home-grown solution.

    – roaima
    Jan 27 at 17:08












  • sorry for causing misunderstanding.but I still don't know how to put a logger command everytime ""echo "cccam... restarting""" occurs.

    – ddinc
    Jan 28 at 9:08











  • add line: logger "cccam... restarting"

    – Radek Radek
    Jan 28 at 10:04

















  • @Thomas.Should be a file in tmp with only the date and time when the process was restarted

    – ddinc
    Jan 27 at 17:05











  • @ddinc logger uses the standard logging facility - an excellent suggestion given you only said you wanted a log line, and didn't specify it had to be a suboptimal home-grown solution.

    – roaima
    Jan 27 at 17:08












  • sorry for causing misunderstanding.but I still don't know how to put a logger command everytime ""echo "cccam... restarting""" occurs.

    – ddinc
    Jan 28 at 9:08











  • add line: logger "cccam... restarting"

    – Radek Radek
    Jan 28 at 10:04
















@Thomas.Should be a file in tmp with only the date and time when the process was restarted

– ddinc
Jan 27 at 17:05





@Thomas.Should be a file in tmp with only the date and time when the process was restarted

– ddinc
Jan 27 at 17:05













@ddinc logger uses the standard logging facility - an excellent suggestion given you only said you wanted a log line, and didn't specify it had to be a suboptimal home-grown solution.

– roaima
Jan 27 at 17:08






@ddinc logger uses the standard logging facility - an excellent suggestion given you only said you wanted a log line, and didn't specify it had to be a suboptimal home-grown solution.

– roaima
Jan 27 at 17:08














sorry for causing misunderstanding.but I still don't know how to put a logger command everytime ""echo "cccam... restarting""" occurs.

– ddinc
Jan 28 at 9:08





sorry for causing misunderstanding.but I still don't know how to put a logger command everytime ""echo "cccam... restarting""" occurs.

– ddinc
Jan 28 at 9:08













add line: logger "cccam... restarting"

– Radek Radek
Jan 28 at 10:04





add line: logger "cccam... restarting"

– Radek Radek
Jan 28 at 10:04













0














I think you can also add -x with shell script and redirect that to a logfile. I use it to log and debug few shell scripts



Something like this



sh -x your_script.sh 2> logfile.log





share|improve this answer























  • Thanks for the replies

    – ddinc
    Jan 28 at 18:07











  • don't know if I got it right but both suggestions produce no logs #!/bin/sh if ps x |grep -v grep |grep -c cccam_2.3.2 >/dev/null then echo "cccam... ok" else echo "cccam... restarting" /var/bin/cccam_2.3.2 & sh -x cccam.sh 2> logfile.log fi

    – ddinc
    Jan 29 at 9:29











  • @ddinc what do you see if you run the sh -x your_script.sh 2> logfile.log outside the script. This should create a log of the shell script while its running into the logfile you mention in the same location.

    – Atul
    Jan 29 at 15:19












  • get this:root@dm820:/var/bin# sh -x cccam.sh 2> logfile.log cccam... ok root@dm820:/var/bin# cccam.sh cccam... ok root@dm820:/var/bin# no log though

    – ddinc
    Jan 30 at 8:20











  • [root@localhost ~]# sh -x shell.sh 2> log cccam... restarting [root@localhost ~]# cat log + grep -v grep + ps x + grep -c cccam_2.3.2 + echo 'cccam... restarting' + /var/bin/cccam_2.3.2 shell.sh: line 8: /var/bin/cccam_2.3.2: No such file or directory I did a small test on one my VM using your code and see a log like this. I didnt had the right files so i got error. Is this close to what you need ?

    – Atul
    Jan 30 at 10:50
















0














I think you can also add -x with shell script and redirect that to a logfile. I use it to log and debug few shell scripts



Something like this



sh -x your_script.sh 2> logfile.log





share|improve this answer























  • Thanks for the replies

    – ddinc
    Jan 28 at 18:07











  • don't know if I got it right but both suggestions produce no logs #!/bin/sh if ps x |grep -v grep |grep -c cccam_2.3.2 >/dev/null then echo "cccam... ok" else echo "cccam... restarting" /var/bin/cccam_2.3.2 & sh -x cccam.sh 2> logfile.log fi

    – ddinc
    Jan 29 at 9:29











  • @ddinc what do you see if you run the sh -x your_script.sh 2> logfile.log outside the script. This should create a log of the shell script while its running into the logfile you mention in the same location.

    – Atul
    Jan 29 at 15:19












  • get this:root@dm820:/var/bin# sh -x cccam.sh 2> logfile.log cccam... ok root@dm820:/var/bin# cccam.sh cccam... ok root@dm820:/var/bin# no log though

    – ddinc
    Jan 30 at 8:20











  • [root@localhost ~]# sh -x shell.sh 2> log cccam... restarting [root@localhost ~]# cat log + grep -v grep + ps x + grep -c cccam_2.3.2 + echo 'cccam... restarting' + /var/bin/cccam_2.3.2 shell.sh: line 8: /var/bin/cccam_2.3.2: No such file or directory I did a small test on one my VM using your code and see a log like this. I didnt had the right files so i got error. Is this close to what you need ?

    – Atul
    Jan 30 at 10:50














0












0








0







I think you can also add -x with shell script and redirect that to a logfile. I use it to log and debug few shell scripts



Something like this



sh -x your_script.sh 2> logfile.log





share|improve this answer













I think you can also add -x with shell script and redirect that to a logfile. I use it to log and debug few shell scripts



Something like this



sh -x your_script.sh 2> logfile.log






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 28 at 17:00









AtulAtul

3502518




3502518












  • Thanks for the replies

    – ddinc
    Jan 28 at 18:07











  • don't know if I got it right but both suggestions produce no logs #!/bin/sh if ps x |grep -v grep |grep -c cccam_2.3.2 >/dev/null then echo "cccam... ok" else echo "cccam... restarting" /var/bin/cccam_2.3.2 & sh -x cccam.sh 2> logfile.log fi

    – ddinc
    Jan 29 at 9:29











  • @ddinc what do you see if you run the sh -x your_script.sh 2> logfile.log outside the script. This should create a log of the shell script while its running into the logfile you mention in the same location.

    – Atul
    Jan 29 at 15:19












  • get this:root@dm820:/var/bin# sh -x cccam.sh 2> logfile.log cccam... ok root@dm820:/var/bin# cccam.sh cccam... ok root@dm820:/var/bin# no log though

    – ddinc
    Jan 30 at 8:20











  • [root@localhost ~]# sh -x shell.sh 2> log cccam... restarting [root@localhost ~]# cat log + grep -v grep + ps x + grep -c cccam_2.3.2 + echo 'cccam... restarting' + /var/bin/cccam_2.3.2 shell.sh: line 8: /var/bin/cccam_2.3.2: No such file or directory I did a small test on one my VM using your code and see a log like this. I didnt had the right files so i got error. Is this close to what you need ?

    – Atul
    Jan 30 at 10:50


















  • Thanks for the replies

    – ddinc
    Jan 28 at 18:07











  • don't know if I got it right but both suggestions produce no logs #!/bin/sh if ps x |grep -v grep |grep -c cccam_2.3.2 >/dev/null then echo "cccam... ok" else echo "cccam... restarting" /var/bin/cccam_2.3.2 & sh -x cccam.sh 2> logfile.log fi

    – ddinc
    Jan 29 at 9:29











  • @ddinc what do you see if you run the sh -x your_script.sh 2> logfile.log outside the script. This should create a log of the shell script while its running into the logfile you mention in the same location.

    – Atul
    Jan 29 at 15:19












  • get this:root@dm820:/var/bin# sh -x cccam.sh 2> logfile.log cccam... ok root@dm820:/var/bin# cccam.sh cccam... ok root@dm820:/var/bin# no log though

    – ddinc
    Jan 30 at 8:20











  • [root@localhost ~]# sh -x shell.sh 2> log cccam... restarting [root@localhost ~]# cat log + grep -v grep + ps x + grep -c cccam_2.3.2 + echo 'cccam... restarting' + /var/bin/cccam_2.3.2 shell.sh: line 8: /var/bin/cccam_2.3.2: No such file or directory I did a small test on one my VM using your code and see a log like this. I didnt had the right files so i got error. Is this close to what you need ?

    – Atul
    Jan 30 at 10:50

















Thanks for the replies

– ddinc
Jan 28 at 18:07





Thanks for the replies

– ddinc
Jan 28 at 18:07













don't know if I got it right but both suggestions produce no logs #!/bin/sh if ps x |grep -v grep |grep -c cccam_2.3.2 >/dev/null then echo "cccam... ok" else echo "cccam... restarting" /var/bin/cccam_2.3.2 & sh -x cccam.sh 2> logfile.log fi

– ddinc
Jan 29 at 9:29





don't know if I got it right but both suggestions produce no logs #!/bin/sh if ps x |grep -v grep |grep -c cccam_2.3.2 >/dev/null then echo "cccam... ok" else echo "cccam... restarting" /var/bin/cccam_2.3.2 & sh -x cccam.sh 2> logfile.log fi

– ddinc
Jan 29 at 9:29













@ddinc what do you see if you run the sh -x your_script.sh 2> logfile.log outside the script. This should create a log of the shell script while its running into the logfile you mention in the same location.

– Atul
Jan 29 at 15:19






@ddinc what do you see if you run the sh -x your_script.sh 2> logfile.log outside the script. This should create a log of the shell script while its running into the logfile you mention in the same location.

– Atul
Jan 29 at 15:19














get this:root@dm820:/var/bin# sh -x cccam.sh 2> logfile.log cccam... ok root@dm820:/var/bin# cccam.sh cccam... ok root@dm820:/var/bin# no log though

– ddinc
Jan 30 at 8:20





get this:root@dm820:/var/bin# sh -x cccam.sh 2> logfile.log cccam... ok root@dm820:/var/bin# cccam.sh cccam... ok root@dm820:/var/bin# no log though

– ddinc
Jan 30 at 8:20













[root@localhost ~]# sh -x shell.sh 2> log cccam... restarting [root@localhost ~]# cat log + grep -v grep + ps x + grep -c cccam_2.3.2 + echo 'cccam... restarting' + /var/bin/cccam_2.3.2 shell.sh: line 8: /var/bin/cccam_2.3.2: No such file or directory I did a small test on one my VM using your code and see a log like this. I didnt had the right files so i got error. Is this close to what you need ?

– Atul
Jan 30 at 10:50






[root@localhost ~]# sh -x shell.sh 2> log cccam... restarting [root@localhost ~]# cat log + grep -v grep + ps x + grep -c cccam_2.3.2 + echo 'cccam... restarting' + /var/bin/cccam_2.3.2 shell.sh: line 8: /var/bin/cccam_2.3.2: No such file or directory I did a small test on one my VM using your code and see a log like this. I didnt had the right files so i got error. Is this close to what you need ?

– Atul
Jan 30 at 10:50


















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • 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%2funix.stackexchange.com%2fquestions%2f497017%2fadd-entry-for-a-logfile%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

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?