Can't create log file through adb shell












0















My working directory is /data/local/tmp.



I create and push a shell script file here named get_meminfo.sh.



The core function of it is record the RSS usage and save as a log file, like this: rss_res >> rss.log



But now I find a problem: I can run the script file when I enter the android shell, like ./get_meminfo.sh, and I can see the log file created in the path.



However when I try to run it from adb, like: adb shell /data/local/tmp/get_meminfo.sh, it will get an error: can't create file, read-only file system!










share|improve this question

























  • can you paste output of this command "adb shell id" and after you enter adb shell then execute "id" output on my machine is same for both commands uid=2000(shell) gid=2000(shell) ls -la /data/local/ drwxr-x--x 3 root root 4096 2018-11-22 12:27 . drwxrwx--x 38 system system 4096 2018-11-23 12:57 .. drwxrwx--x 2 shell shell 4096 2018-11-23 16:14 tmp shell:shell has write permission in /data/local/tmp/ so ideally you should be able to execute

    – nkalra0123
    Nov 23 '18 at 10:52
















0















My working directory is /data/local/tmp.



I create and push a shell script file here named get_meminfo.sh.



The core function of it is record the RSS usage and save as a log file, like this: rss_res >> rss.log



But now I find a problem: I can run the script file when I enter the android shell, like ./get_meminfo.sh, and I can see the log file created in the path.



However when I try to run it from adb, like: adb shell /data/local/tmp/get_meminfo.sh, it will get an error: can't create file, read-only file system!










share|improve this question

























  • can you paste output of this command "adb shell id" and after you enter adb shell then execute "id" output on my machine is same for both commands uid=2000(shell) gid=2000(shell) ls -la /data/local/ drwxr-x--x 3 root root 4096 2018-11-22 12:27 . drwxrwx--x 38 system system 4096 2018-11-23 12:57 .. drwxrwx--x 2 shell shell 4096 2018-11-23 16:14 tmp shell:shell has write permission in /data/local/tmp/ so ideally you should be able to execute

    – nkalra0123
    Nov 23 '18 at 10:52














0












0








0








My working directory is /data/local/tmp.



I create and push a shell script file here named get_meminfo.sh.



The core function of it is record the RSS usage and save as a log file, like this: rss_res >> rss.log



But now I find a problem: I can run the script file when I enter the android shell, like ./get_meminfo.sh, and I can see the log file created in the path.



However when I try to run it from adb, like: adb shell /data/local/tmp/get_meminfo.sh, it will get an error: can't create file, read-only file system!










share|improve this question
















My working directory is /data/local/tmp.



I create and push a shell script file here named get_meminfo.sh.



The core function of it is record the RSS usage and save as a log file, like this: rss_res >> rss.log



But now I find a problem: I can run the script file when I enter the android shell, like ./get_meminfo.sh, and I can see the log file created in the path.



However when I try to run it from adb, like: adb shell /data/local/tmp/get_meminfo.sh, it will get an error: can't create file, read-only file system!







android shell adb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 4:39









Alex P.

19.9k1367118




19.9k1367118










asked Nov 23 '18 at 10:24









Fangyuan TanFangyuan Tan

114




114













  • can you paste output of this command "adb shell id" and after you enter adb shell then execute "id" output on my machine is same for both commands uid=2000(shell) gid=2000(shell) ls -la /data/local/ drwxr-x--x 3 root root 4096 2018-11-22 12:27 . drwxrwx--x 38 system system 4096 2018-11-23 12:57 .. drwxrwx--x 2 shell shell 4096 2018-11-23 16:14 tmp shell:shell has write permission in /data/local/tmp/ so ideally you should be able to execute

    – nkalra0123
    Nov 23 '18 at 10:52



















  • can you paste output of this command "adb shell id" and after you enter adb shell then execute "id" output on my machine is same for both commands uid=2000(shell) gid=2000(shell) ls -la /data/local/ drwxr-x--x 3 root root 4096 2018-11-22 12:27 . drwxrwx--x 38 system system 4096 2018-11-23 12:57 .. drwxrwx--x 2 shell shell 4096 2018-11-23 16:14 tmp shell:shell has write permission in /data/local/tmp/ so ideally you should be able to execute

    – nkalra0123
    Nov 23 '18 at 10:52

















can you paste output of this command "adb shell id" and after you enter adb shell then execute "id" output on my machine is same for both commands uid=2000(shell) gid=2000(shell) ls -la /data/local/ drwxr-x--x 3 root root 4096 2018-11-22 12:27 . drwxrwx--x 38 system system 4096 2018-11-23 12:57 .. drwxrwx--x 2 shell shell 4096 2018-11-23 16:14 tmp shell:shell has write permission in /data/local/tmp/ so ideally you should be able to execute

– nkalra0123
Nov 23 '18 at 10:52





can you paste output of this command "adb shell id" and after you enter adb shell then execute "id" output on my machine is same for both commands uid=2000(shell) gid=2000(shell) ls -la /data/local/ drwxr-x--x 3 root root 4096 2018-11-22 12:27 . drwxrwx--x 38 system system 4096 2018-11-23 12:57 .. drwxrwx--x 2 shell shell 4096 2018-11-23 16:14 tmp shell:shell has write permission in /data/local/tmp/ so ideally you should be able to execute

– nkalra0123
Nov 23 '18 at 10:52












1 Answer
1






active

oldest

votes


















0














It seems that you do not quite understand the concept of the current working dirtectory.



The rss_res >> rss.log command creates rss.log in the current working dirtectory. Which in case of the following command sequence is /data/local/tmp:



adb shell
cd /data/local/tmp
./get_meminfo.sh


So rss.log gets created in /data/local/tmp which is world writable.



But in case of adb shell /data/local/tmp/get_meminfo.sh the cwd is the / root folder. Which is not writable and the command fails.



The easiest way to mitigate that is to use the absolute path for your log file inside of your script like this rss_res >> /data/local/tmp/rss.log






share|improve this answer
























  • Very thanks! It totally solved my problem.

    – Fangyuan Tan
    Nov 25 '18 at 10:06











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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%2fstackoverflow.com%2fquestions%2f53444858%2fcant-create-log-file-through-adb-shell%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














It seems that you do not quite understand the concept of the current working dirtectory.



The rss_res >> rss.log command creates rss.log in the current working dirtectory. Which in case of the following command sequence is /data/local/tmp:



adb shell
cd /data/local/tmp
./get_meminfo.sh


So rss.log gets created in /data/local/tmp which is world writable.



But in case of adb shell /data/local/tmp/get_meminfo.sh the cwd is the / root folder. Which is not writable and the command fails.



The easiest way to mitigate that is to use the absolute path for your log file inside of your script like this rss_res >> /data/local/tmp/rss.log






share|improve this answer
























  • Very thanks! It totally solved my problem.

    – Fangyuan Tan
    Nov 25 '18 at 10:06
















0














It seems that you do not quite understand the concept of the current working dirtectory.



The rss_res >> rss.log command creates rss.log in the current working dirtectory. Which in case of the following command sequence is /data/local/tmp:



adb shell
cd /data/local/tmp
./get_meminfo.sh


So rss.log gets created in /data/local/tmp which is world writable.



But in case of adb shell /data/local/tmp/get_meminfo.sh the cwd is the / root folder. Which is not writable and the command fails.



The easiest way to mitigate that is to use the absolute path for your log file inside of your script like this rss_res >> /data/local/tmp/rss.log






share|improve this answer
























  • Very thanks! It totally solved my problem.

    – Fangyuan Tan
    Nov 25 '18 at 10:06














0












0








0







It seems that you do not quite understand the concept of the current working dirtectory.



The rss_res >> rss.log command creates rss.log in the current working dirtectory. Which in case of the following command sequence is /data/local/tmp:



adb shell
cd /data/local/tmp
./get_meminfo.sh


So rss.log gets created in /data/local/tmp which is world writable.



But in case of adb shell /data/local/tmp/get_meminfo.sh the cwd is the / root folder. Which is not writable and the command fails.



The easiest way to mitigate that is to use the absolute path for your log file inside of your script like this rss_res >> /data/local/tmp/rss.log






share|improve this answer













It seems that you do not quite understand the concept of the current working dirtectory.



The rss_res >> rss.log command creates rss.log in the current working dirtectory. Which in case of the following command sequence is /data/local/tmp:



adb shell
cd /data/local/tmp
./get_meminfo.sh


So rss.log gets created in /data/local/tmp which is world writable.



But in case of adb shell /data/local/tmp/get_meminfo.sh the cwd is the / root folder. Which is not writable and the command fails.



The easiest way to mitigate that is to use the absolute path for your log file inside of your script like this rss_res >> /data/local/tmp/rss.log







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 4:36









Alex P.Alex P.

19.9k1367118




19.9k1367118













  • Very thanks! It totally solved my problem.

    – Fangyuan Tan
    Nov 25 '18 at 10:06



















  • Very thanks! It totally solved my problem.

    – Fangyuan Tan
    Nov 25 '18 at 10:06

















Very thanks! It totally solved my problem.

– Fangyuan Tan
Nov 25 '18 at 10:06





Very thanks! It totally solved my problem.

– Fangyuan Tan
Nov 25 '18 at 10:06


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • 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%2fstackoverflow.com%2fquestions%2f53444858%2fcant-create-log-file-through-adb-shell%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

Berounka

Fiat S.p.A.

Type 'String' is not a subtype of type 'int' of 'index'