Add entry for a logfile
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
What do you mean byadd a logfile line
? Do you want to send theecho
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
add a comment |
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
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
scripting logs
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 byadd a logfile line
? Do you want to send theecho
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
add a comment |
What do you mean byadd a logfile line
? Do you want to send theecho
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
add a comment |
2 Answers
2
active
oldest
votes
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.
@Thomas.Should be a file in tmp with only the date and time when the process was restarted
– ddinc
Jan 27 at 17:05
@ddinclogger
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
add a comment |
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
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
@Thomas.Should be a file in tmp with only the date and time when the process was restarted
– ddinc
Jan 27 at 17:05
@ddinclogger
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
add a comment |
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.
@Thomas.Should be a file in tmp with only the date and time when the process was restarted
– ddinc
Jan 27 at 17:05
@ddinclogger
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
add a comment |
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.
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.
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
@ddinclogger
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
add a comment |
@Thomas.Should be a file in tmp with only the date and time when the process was restarted
– ddinc
Jan 27 at 17:05
@ddinclogger
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What do you mean by
add a logfile line
? Do you want to send theecho
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