Register
It is currently Wed Jul 23, 2014 7:56 pm

Need a really simple script but I can't figure it out :(


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Fri Apr 29, 2011 3:02 pm   

Joined: Fri Apr 29, 2011 2:52 pm
Posts: 8
Okay so I'm on typing a script for android operating system (which is almost identical in linux when using bash scripts :D) but I can't make the correct script to do what I want.

There is a directory
Code:
/sys/devices/virtual/bdi


Inside that directory there are folders that all contain this file named
Code:
read_ahead_kb


So I tried changing the value of that file in all those folders by doing this but it doesn't take effect :( And I need it to set the value or it won't boot into the phone (I set a infinite loop so that it continuously tries to change the values of that file in all the folders, but since it won't boot until it does change it and since it won't change it, it never boots). Any help with this would be awesome :D

Here is my attempt at the code:

Code:
#!/system/bin/sh

# SD CARD TWEAKS
SD=`ls -d /sys/devices/virtual/bdi/*`;
CHECK_SD=`cat /sys/devices/virtual/bdi/179:0/read_ahead_kb`;

until [ "$CHECK_SD" = "1024"]
do
   for fix in $SD
   do
      echo 1024 $fix/read_ahead_kb;
   done
done


Help is appreciated :))


Top
 Profile  
 PostPosted: Fri Apr 29, 2011 3:18 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
Hi

Code:
for dir in /sys/devices/virtual/bdi/*/
do echo "1024" > "${dir}read_ahead_kb"
done
done!


Top
 Profile  
 PostPosted: Fri Apr 29, 2011 7:28 pm   

Joined: Fri Apr 29, 2011 2:52 pm
Posts: 8
thanks but i have another question.

why exactly didn't mine work?

:D

edit: will this edited one work? I need it to check it if the values were set it will exit :D

Code:
until [ "$CHECK_SD_CACHE" = "1024" ]
   do
      if [ "$CHECK_SD_CACHE" = "128" ]
         then
            for fix in /sys/devices/virtual/bdi/*/
               do echo "1024" > "${fix}read_ahead_kb"
            done
         else
         break
      fi
done


Top
 Profile  
 PostPosted: Fri Apr 29, 2011 8:02 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
because /sys/devices/virtual/bdi/179:0/read_ahead_kb is never re-read.

why do you think the script should stop when this file's content is 1024 ?

no need of an until-loop, you could do this :
Code:
for dir in /sys/devices/virtual/bdi/*/
do if [ "$dir" = "/sys/devices/virtual/bdi/179:0/" ] && [ "$(cat ${dir}read_ahead_kb)" = 1024 ]
   then break
   else echo "1024" > "${dir}read_ahead_kb"
   fi
done
but I'm not sure it is useful, because the for-loop I gave previously should overwrite every read_ahead_kb file in every directory under /sys/devices/virtual/bdi


Top
 Profile  
 PostPosted: Fri Apr 29, 2011 8:27 pm   

Joined: Fri Apr 29, 2011 2:52 pm
Posts: 8
Watael wrote:
because /sys/devices/virtual/bdi/179:0/read_ahead_kb is never re-read.

why do you think the script should stop when this file's content is 1024 ?

no need of an until-loop, you could do this :
Code:
for dir in /sys/devices/virtual/bdi/*/
do if [ "$dir" = "/sys/devices/virtual/bdi/179:0/" ] && [ "$(cat ${dir}read_ahead_kb)" = 1024 ]
   then break
   else echo "1024" > "${dir}read_ahead_kb"
   fi
done
but I'm not sure it is useful, because the for-loop I gave previously should overwrite every read_ahead_kb file in every directory under /sys/devices/virtual/bdi


GENIUS! :D

I was just trying to come up with something like that I JUST like 2 seconds ago found that && means and in bash :D

and || means or :D they're conditional command operators or something like that but thanks :D


Top
 Profile  
 PostPosted: Sat Apr 30, 2011 12:03 am   

Joined: Fri Apr 29, 2011 2:52 pm
Posts: 8
Watael wrote:
because /sys/devices/virtual/bdi/179:0/read_ahead_kb is never re-read.

why do you think the script should stop when this file's content is 1024 ?

no need of an until-loop, you could do this :
Code:
for dir in /sys/devices/virtual/bdi/*/
do if [ "$dir" = "/sys/devices/virtual/bdi/179:0/" ] && [ "$(cat ${dir}read_ahead_kb)" = 1024 ]
   then break
   else echo "1024" > "${dir}read_ahead_kb"
   fi
done
but I'm not sure it is useful, because the for-loop I gave previously should overwrite every read_ahead_kb file in every directory under /sys/devices/virtual/bdi


hey it didn't work :( I just tried it and the values didn't set :(

i fixed it :D it was just a little bit of adding this and that to make it work ;)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP